ããã¾ãè¦ãããªãæ°ããã Vim ã® Tips 11 + 1 é¸
ã©ããããç¡æ²æ±°ãã¦ããã¾ãã Vimmer + Pythonistaã ç¥ã㦠Vist... ããããããã£ã¡ã¯ç¸èµ·ãæªãã ãã®è¨äºã¯ Vim Advent Calendar 2015 ã® 24æ¥ç®ã®è¨äºã¨ãªãã¾ãã
ã¯ããã«
èªåã Mac OS X ããã³ Linux ããæã£ã¦ããªããããWindows ã§åããªãã£ããããããªããã
ã¨ããããæ¸ããã¨æã£ã¦ãããã®ãæªå®æãªã®ã§ãä»ã§ã¯ãã¾ãè¦ããã¨ããªã ~/.vimrc
ã®ã便å©è¨å®ãã¾ã¨ãã¾ãã
ä¸è¦ãªããã©ã«ããã©ã°ã¤ã³ãæ¢ãã
ããã£ã±ãªããã¶ã£é£ãã è¨å®ã§ãããåã¯ä¸è¦ãªããã©ã«ããã©ã°ã¤ã³ããã¹ã¦æ¢ãã¦ãã¾ãã 以ä¸è¨å®
let g:loaded_gzip = 1 let g:loaded_tar = 1 let g:loaded_tarPlugin = 1 let g:loaded_zip = 1 let g:loaded_zipPlugin = 1 let g:loaded_rrhelper = 1 let g:loaded_2html_plugin = 1 let g:loaded_vimball = 1 let g:loaded_vimballPlugin = 1 let g:loaded_getscript = 1 let g:loaded_getscriptPlugin = 1 let g:loaded_netrw = 1 let g:loaded_netrwPlugin = 1 let g:loaded_netrwSettings = 1 let g:loaded_netrwFileHandlers = 1
ããã ~/.vimrc
ã®å
é ã«è¨è¼ãããã¨ã§ã以ä¸ã®ãã©ã°ã¤ã³ã®èªã¿è¾¼ã¿ãï¼å®å
¨ã«ã¯ï¼è¡ããã¾ããã
- GZip ãã¡ã¤ã«ã®å±éã»é²è¦§
- Tar ãã¡ã¤ã«ã®å±éã»é²è¦§
- Zip ãã¡ã¤ã«ã®é²è¦§ã»å±é
--remote-wait
ã¨ãTOhtml
- Vimball ã®å±éã¨ãã¤ã³ã¹ãã¼ã«ã¨ã
GetLatestVimScripts
ã³ãã³ãã¨ãNetrw
ç³»å ¨é¨
ãããã®ãã©ã°ã¤ã³ã¯å人çã«ã¯å ¨ã使ããªãããåã£ã¦ããã¾ãã ããã¼ãããªã®çµ¶å¯¾ä½¿ããªãããã¨ããæ¹ã¯åã£ã¦ãããããï¼ããã©ã«ããã©ã°ã¤ã³ãªã®ã§ãµã¤ãã¨ãã§ã¯ããããå¯è½æ§ãããã¾ãããã°ã£ã¦ãèªå·±è²¬ä»»ã§ï¼ï¼
GUI Vim 以å¤ã§ matchparen ãããã
()
ã®å¯¾å¿ãªã©ã表示ãã¦ããã matchparen
ã¨ããæ©è½ã§ãã Terminal ä¸ã§ã¯ã«ã¼ã½ã«ãã¨ã¦ãè¦ã«ãããªãããåã£ã¦ããã¾ãã以ä¸è¨å®
if !has('gui_running') let g:loaded_matchparen = 1 endif
Vim å
é¨ã§å©ç¨ãã PATH
ã®è¨å®
ãTerminal ããèµ·åããå ´åã¯åããã© GUI ã§èµ·åããå ´åã¯åããªãããªã©ã®ç¾è±¡ã¯ã ãããããã§ãã
åã¯é¢æ°ãå®ç¾©ãã¦æå®ããããã¹ãåå¨ãã $PATH
ã«åå¨ãã¦ããªãå ´åã®ã¿è¿½å ããããã«ãã¦ãã¾ãã
ããã«ããè¤æ°ã® OS ã§ãã¹ãç°ãªãå ´åã§ããããªã«è¨å®ã§ãã¾ãã
function! AddPath(pathlist) abort " {{{ let pathlist = split($PATH, s:delimiter) for path in map(filter(a:pathlist, 'v:val'), 'expand(v:val)') if isdirectory(path) && index(pathlist, path) == -1 call insert(pathlist, path, 0) endif endfor let $PATH = join(pathlist, s:delimiter) endfunction " }}} call AddPath([ \ '/usr/local/texlive/2013/bin/x86_64-linux', \ '/usr/local/texlive/2013/bin/x86_64-darwin', \ '~/.pyenv/bin', \ '~/.plenv/bin', \ '~/.rbenv/bin', \ '~/.ndenv/bin', \ '~/.pyenv/shims', \ '~/.plenv/shims', \ '~/.rbenv/shims', \ '~/.ndenv/shims', \ '~/.anyenv/envs/pyenv/bin', \ '~/.anyenv/envs/plenv/bin', \ '~/.anyenv/envs/rbenv/bin', \ '~/.anyenv/envs/ndenv/bin', \ '~/.anyenv/envs/pyenv/shims', \ '~/.anyenv/envs/plenv/shims', \ '~/.anyenv/envs/rbenv/shims', \ '~/.anyenv/envs/ndenv/shims', \ '~/.cabal/bin', \ '~/.vim/bundle/vim-themis/bin', \])
ãã¦ã¹ã®ããã«ã¯ãªãã¯ã«ããè²¼ä»ããããã
ãã¾ã«ã¯ãªãã¯ãã¦ãã¾ã£ã¦ã¨ã¦ãé¢åãªã®ã§å®å ¨ã«åãã¾ã
map <MiddleMouse> <Nop> map <2-MiddleMouse> <Nop> map <3-MiddleMouse> <Nop> map <4-MiddleMouse> <Nop> imap <MiddleMouse> <Nop> imap <2-MiddleMouse> <Nop> imap <3-MiddleMouse> <Nop> imap <4-MiddleMouse> <Nop>
å ¥åã¢ã¼ãã§ã¯ Emacs çãªç§»åãå¯è½ã«ãã
å¤§ä½ Normal ã¢ã¼ãã§ç§»åããããã«ä½ãæ £ãã¦ãã¾ãããã¿ã¼ããã«ãªã©ã§ã¯ Emacs ãã¼ãã¤ã³ãã£ã³ã°ãä¸è¬çãªã®ã§å ¥åä¸ã§ã Emacs 風ãã¼ãã¤ã³ãã§ç§»åã§ããããã«ãã¦ãã¾ãã
inoremap <C-a> <C-o>^ inoremap <C-e> <C-o>$ inoremap <C-f> <C-o>w inoremap <C-b> <C-o>b inoremap <C-d> <C-o>x " Emacs çãããªããã©ãããã inoremap <C-h> <C-o>h inoremap <C-j> <C-o>j inoremap <C-k> <C-o>k inoremap <C-l> <C-o>l
ã¦ã£ã³ãã¦ãµã¤ãºãç°¡åã«å¤æ´
ããã©ã«ãã§ã¯ Ctrl-w <
ã¨ãé£ç¶ã§æ¼ãã®ã¯å¤§å¤ãªã®ã§ Shift
+ ãã£ãã«ä½¿ããªãç¢å°ãã¼ãå²ãå½ã¦ã¦ãã¾ãã
nnoremap <S-Left> <C-w><<CR> nnoremap <S-Right> <C-w>><CR> nnoremap <S-Up> <C-w>-<CR> nnoremap <S-Down> <C-w>+<CR>
ãã°ã«ç³»ãããã³ã°
è¨å®ã®ãã°ã«ç¨ã« <Leader>s
(Switch) ãå²ãå½ã¦ã¦ãã¾ãã
ããã§å³åãªã®ã¯ <Leader>s
ã« <Plug>(my-switch)
ãã¾ãå²ãå½ã¦ã¦ããã®å¾ <Plug>(my-switch)
ã使ã£ã¦å®éã®ãããã³ã°ãå²ãå½ã¦ã¦ããã¨ããã§ãããããããã¨ã«ãã :map
ã§ãããã³ã°ã表示ããéã«ãããããããªãã¾ãï¼ã㨠prefix å¤ããããªã£ããç°¡åã«å¤ããããï¼ã
nnoremap <Plug>(my-switch) <Nop> nmap <Leader>s <Plug>(my-switch) nnoremap <silent> <Plug>(my-switch)s :<C-u>setl spell! spell?<CR> nnoremap <silent> <Plug>(my-switch)l :<C-u>setl list! list?<CR> nnoremap <silent> <Plug>(my-switch)t :<C-u>setl expandtab! expandtab?<CR> nnoremap <silent> <Plug>(my-switch)w :<C-u>setl wrap! wrap?<CR> nnoremap <silent> <Plug>(my-switch)p :<C-u>setl paste! paste?<CR> nnoremap <silent> <Plug>(my-switch)b :<C-u>setl scrollbind! scrollbind?<CR> nnoremap <silent> <Plug>(my-switch)y :call <SID>toggle_syntax()<CR> function! s:toggle_syntax() abort if exists('g:syntax_on') syntax off redraw echo 'syntax off' else syntax on redraw echo 'syntax on' endif endfunction
w!! 㧠sudo ã§ä¿å
便å©ãããã®ã§ãçµæ§ä»ã§ãè¦ã¾ããç´¹ä»ãåã®å ´å㯠sudo.vim
ã§ä¸æ¸ããã¦ãã¾ãã¾ããããã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ãã¦ããªãç°å¢ã§ãç°¡æçã«ä½¿ããããã«è¨å®ãã¦ããã¾ãã
cabbr w!! w !sudo tee > /dev/null %
ããæãã« Vim ã® mkview/loadview æ©è½ãèªååãã
Vim ã® mkview/loadview æ©è½ã使ããã¨ã§æãããã¿ã®ã¬ãã«ãã«ã¼ã½ã«ä½ç½®ãªã©ãä¿æãã¦ãããã¨ãã§ããä¸æã«ä½¿ãã¨ä¾¿å©ãªã®ã§ãããèªååããã¨èª¤çãå¤ãããæåã§è¡ã£ã¦ããæ¹ãå¤ãã¨æãã¾ãã 以ä¸ã®ããã« view ã使ãããï¼ä½¿ãã¹ããï¼ã¿ãããªé¢æ°ãåã¾ãã¦ããã¨ããæãã«èªåååºæ¥ã¾ãã
function! s:is_view_available() abort " {{{ if !&buflisted || &buftype !=# '' return 0 elseif !filewritable(expand('%:p')) return 0 endif return 1 endfunction " }}} function! s:mkview() abort " {{{ if s:is_view_available() silent! mkview endif endfunction " }}} function! s:loadview() abort " {{{ if s:is_view_available() silent! loadview endif endfunction " }}} autocmd MyAutoCmd BufWinLeave ?* call s:mkview() autocmd MyAutoCmd BufReadPost ?* call s:loadview()
è¨å®ãã¡ã¤ã«ã®ãªãã¼ã
Vim ã¯è¨å®ãã¡ã¤ã«ãæ¸ãããã«å©ç¨ããæéãæ¯è¼çã«ï¼é£èºçã«ï¼é·ãã¨ãã£ã¿ãªã®ã§ãããã£ã¨æ¸ãã¦ããã£ã¨è©¦ããããã«ãªãã¼ãããããã³ã°ã§è¡ããããã«ãã¦ãã¾ãã
ãªãã¼ãä¸ã«é¢æ°ã®ä¸æ¸ããåºæ¥ãªãã®ã§ has('vim_starting')
ã§å²ã£ã¦ãã¾ãã
if has('vim_starting') function s:reload_vimrc() abort execute printf('source %s', $MYVIMRC) if has('gui_running') execute printf('source %s', $MYGVIMRC) endif redraw echo printf('.vimrc/.gvimrc has reloaded (%s).', strftime('%c')) endfunction endif nmap <silent> <Plug>(my-reload-vimrc) :<C-u>call <SID>reload_vimrc()<CR> nmap <Leader><Leader>r <Plug>(my-reload-vimrc)
ç¹å®ãã¡ã¤ã«ã®è¦ªãã£ã¬ã¯ããªã¼ã«ã¯ã³ã¹ãããã§ç§»åãã
ç¹å®ãã¡ã¤ã«ã®è¦ªãã£ã¬ã¯ããªã¼ã«ç§»åããããã¨ã£ã¦çµæ§ããã¨æãã¾ãã
æã§æã£ã¦ãããã®ã§ãããå²ã¨é¢åãªã®ã§é¢æ°åãã¦ãã¾ãã
ã¾ã my-workon-post
ã¨ããã¦ã¼ã¶ã¼å®ç¾© autocmd ãå¼ã³åºããã¨ã§ä»»æã®å¦çãå®è¡ã§ããããã«ãã¦ãã¾ãï¼ãããå©ç¨ã㦠Vimfiler ã®ãã£ã¬ã¯ããªãå¤æ´ããããã«ãã¦ãï¼ã
function! s:workon(dir, bang) abort let dir = (a:dir ==# '' ? expand('%') : a:dir) " convert filename to directory if required if filereadable(dir) let dir = fnamemodify(expand(dir),':p:h') else let dir = fnamemodify(dir, ':p') endif " change directory to specified directory if isdirectory(dir) silent execute 'cd ' . fnameescape(dir) if a:bang ==# '' redraw | echo 'Working on: '.dir if v:version > 703 || (v:version == 703 && has('patch438')) doautocmd <nomodeline> MyAutoCmd User my-workon-post else doautocmd MyAutoCmd User my-workon-post endif endif endif endfunction autocmd MyAutoCmd VimEnter * call s:workon(expand('<afile>'), 1) command! -nargs=? -complete=dir -bang Workon call s:workon('<args>', '<bang>')
ãããè¨è¼ãã㨠autocmd MyAutoCmd VimEnter * ...
ã®é¨åã«ãã£ã¦èµ·åæã«ãã¡ã¤ã«ãæå®ããã¦ãããããã®ãã¡ã¤ã«ã®è¦ªãã£ã¬ã¯ããªã«èªåçã«ç§»åãã¾ããã¾ã :Workon
ã¨ããã³ãã³ããå®ç¾©ãã¦ããã®ã§ç·¨éä¸ã®ãããã¡ã§ :Workon
ã¨ããã¨ç·¨éä¸ã®ãããã¡ã®è¦ªãã£ã¬ã¯ããªã«ç§»åã§ãã¾ãã
ã¾ããå
ã«ãè¿°ã¹ã¾ããã my-workon-post
ã¨ããã¦ã¼ã¶ã¼é©å® autocmd ãå¼ã³åºãã¦ããã®ã§ãä¾ãã°ä¸è¨ã®ããã«å©ç¨ãããã¨ãåºæ¥ã¾ãããã®ããã㯠s:workon()
ã«æ¸ãã¦ãè¯ãã®ã§ãããç´äº¤æ§ãé
æ
®ããçµæã§ãã
" :Workon ã³ãã³ãå¾ãªã©ã« Vimfiler ãéãã¦ããå ´å㯠:Workon ã§ç§»åãããã£ã¬ã¯ããªã« " Vimfiler ã移åãã function! s:cd_all_vimfiler(path) abort let current_nr = winnr() try for winnr in filter(range(1, winnr('$')), \ "getwinvar(v:val, '&filetype') ==# 'vimfiler'") call vimfiler#util#winmove(winnr) call vimfiler#mappings#cd(a:path) endfor finally call vimfiler#util#winmove(current_nr) endtry endfunction autocmd MyAutoCmd User my-workon-post call s:cd_all_vimfiler(getcwd())
ï¼çªå¤ç·¨ï¼Unite menu ããã£ã¡ã便å©ã«ãã
Shougoware 代表ä½ã§ãã unite.vim ã«ã¯åºå®ã¡ãã¥ã¼ã表示ããããã® menu
ã½ã¼ã¹ãããã®ã§ããããã«ããªã©ã«æ¸ãã¦ããæ¹æ³ã¯ã³ãã³ããç´æ¥å®è¡ããæ¹æ³ãªã®ã§ããããã®ãã¡ã¤ã« split ã§éããããã¨ãã«å¯¾å¿ã§ãã¾ããï¼ãã㶠edit xxxxxx
ã£ã¦æ¸ãããï¼ã
ããã§ä»¥ä¸ã®æ§ãªãã«ãã¼é¢æ°ãå®ç¾©ãã¾ãã
function! s:register_filemenu(name, description, precursors) abort " {{{ " find the length of the longest name let max_length = max(map( \ filter(deepcopy(a:precursors), 'len(v:val) > 1'), \ 'len(v:val[0])' \)) let format = printf('%%-%ds : %%s', max_length) let candidates = [] for precursor in a:precursors if len(precursor) == 1 call add(candidates, [ \ precursor[0], \ '', \]) elseif len(precursor) >= 2 let name = precursor[0] let desc = precursor[1] let path = get(precursor, 2, '') let path = resolve(expand(empty(path) ? desc : path)) let kind = isdirectory(path) ? 'directory' : 'file' call add(candidates, [ \ printf(format, name, desc), \ path, \]) else let msg = printf( \ 'A candidate precursor must has 1 or more than two terms : %s', \ string(precursor) \) call add(candidates, [ \ 'ERROR : ' . msg, \ '', \]) endif endfor let menu = {} let menu.candidates = candidates let menu.description = a:description let menu.separator_length = max(map( \ deepcopy(candidates), \ 'len(v:val[0])', \)) if menu.separator_length % 2 != 0 let menu.separator_length += 1 endif function! menu.map(key, value) abort let word = a:value[0] let path = a:value[1] if empty(path) if word ==# '-' let word = repeat('-', self.separator_length) else let length = self.separator_length - (len(word) + 3) let word = printf('- %s %s', word, repeat('-', length)) endif return { \ 'word': '', \ 'abbr': word, \ 'kind': 'common', \ 'is_dummy': 1, \} else let kind = isdirectory(path) ? 'directory' : 'file' let directory = isdirectory(path) ? path : fnamemodify(path, ':h') return { \ 'word': word, \ 'abbr': printf('[%s] %s', toupper(kind[0]), word), \ 'kind': kind, \ 'action__path': path, \ 'action__directory': directory, \} endif endfunction " register to 'g:unite_source_menu_menus' let g:unite_source_menu_menus = get(g:, 'unite_source_menu_menus', {}) let g:unite_source_menu_menus[a:name] = menu endfunction " }}} " 使ç¨ä¾ call s:register_filemenu('shortcut', 'Shortcut menu', [ \ ['vim'], \ [ \ 'vimrc', \ fnamemodify(resolve($MYVIMRC), ':~'), \ ], \ [ \ 'gvimrc', \ fnamemodify(resolve($MYGVIMRC), ':~'), \ ], \ [ \ 'vimshrc', \ '~/.vim/vimshrc', \ ], \ [ \ 'vim', \ '~/.vim', \ ], \ [ \ 'bundle', \ '~/.vim/bundle', \ ], \ [ \ 'ftplugin', \ '~/.vim/ftplugin', \ ], \ ['zsh'], \ [ \ 'zshrc', \ '~/.config/zsh/.zshrc', \ ], \ [ \ 'rc/theme.dust.zsh', \ '~/.config/zsh/rc/theme.dust.zsh', \ ], \ [ \ 'rc/configure.applications.zsh', \ '~/.config/zsh/rc/configure.applications.zsh', \ ], \ [ \ 'zsh', \ '~/.config/zsh', \ ], \ ['tmux'], \ [ \ 'tmux.conf', \ '~/.tmux.conf', \ ], \ [ \ 'tmux-powerlinerc', \ '~/.tmux-powerlinerc', \ ], \ [ \ 'tmux-powerline.conf', \ '~/.config/tmux/tmux-powerline.conf', \ ], \ [ \ 'tmux', \ '~/.config/tmux', \ ], \ ['others'], \ [ \ 'gitconfig', \ '~/.gitconfig', \ ], \ [ \ 'gitignore', \ '~/.gitignore', \ ], \ [ \ 'pymolrc', \ '~/.pymolrc', \ ], \ [ \ 'vimperatorrc', \ '~/.vimperatorrc', \ ], \ [ \ 'latexmkrc', \ '~/.latexmkrc', \ ], \ [ \ 'jupyter custom.css', \ '~/.jupyter/custom/custom.css', \ ], \ [ \ 'jupyter custom.js', \ '~/.jupyter/custom/custom.js', \ ], \])
ãã®ãã«ãã¼é¢æ°ãå©ç¨ãã¦ä½æãã Unite menu
ã§ã¯ãUnite file
ã Unite directory
ã®ããã« right
ã¢ã¯ã·ã§ã³ãªã©ãæå¹ã«ãªãã¾ããUnite menu
ã§ãã¡ã¤ã«ã®éãæ¹ãæå®ãããã¦å°ã£ã¦ããæ¹ã¯æ¯é試ãã¦ã¿ã¦ãã ããã
ãããã«
éã ãã ãã㨠2 min ãããªããä»æ¹ããªã