vimã§ãã¼ãããã³ã°ããéã«èããã»ãããããã¨
ãã®è¨äºã¯Vim Advent Calendar 2012ã®153æ¥ç®ã®è¨äºã§ãã
152æ¥ç®ã¯manga_osyoããã«ããVim ã§ç¾å¨ã®æ¤ç´¢ä½ç½®ã表示ããã§ããã
vimãããç¨åº¦ä½¿ãããã«ãªãã¨ãããæä½(æ©è½)ãç´ æ©ãå¼ã³åºããããªã©ã§ãã¼ããããè¨å®ããããã«ãªãã¾ãã
ã§ãããæ°ãããã¼ã®ä¸ã§ã©ã®ãã¼ã«æ©è½ãå²ãå½ã¦ããçµæ§é ãæ©ã¾ãããã¨ãå¤ããã¨æãã¾ãã
ã¡ããã¨æ¢åã®ãã¼ã®æ©è½ãæèãã¦å²ãå½ã¦ãããã°è¯ãã§ããããã¾ã«ããã£ããã®ãã¼æ½°ãã¡ããã®ï¼ãã¨æããããª
ãã¼ãæ½°ãã¦ããã®ãè¦ããã¾ã(åºå
¸:vimrcèªæ¸ä¼ã«ã¦)ã
æå³ãã¦ãã£ã¦ãããªãããã§ããããããã¬ã¾ã¾éè¦ãªãã¼ãæ½°ãã¦ãã®æ©è½ãå
¨ã使ããªãã¨ããçµæ§ãã£ãããªããã®ã§ãã
ããã§ããã¼ãããã³ã°ããéã«èããã»ãããããã¨ãè¨è¿°ãããã¨æãã¾ãã
ãã¤ãã¼ãããã³ã°ãããï¼
ã¾ãã¯ã©ãããæã«ãã¼ãããã³ã°ãããã«ã¤ãã¦ç°¡åã«ã¾ã¨ãããã¨æãã¾ãã
pluginã®å¼ã³åºãã«å²ãå½ã¦ã
便å©ãªpluginå ¥ãããç´ æ©ãå¼ã³åºãããã«ãã¼ããããè¨å®ãããã¨æãã®ãvimmerã®ããã¨ãããã®ã§ãã ç¹ã«ã³ãã³ãã®å ¥åãå¿ è¦ãªpluginã§ã¯æ¯åã³ãã³ããå ¥åããã®ã¯é¢åãªã®ã§ãã¼ããããè¨å®ãããã¨ãå¤ãã§ãã ä¾ãã°ãpluginã®Uniteã®ã³ãã³ããå®ç¾©ããå ´å以ä¸ã®æ§ã«è¨å®ãã¾ãã
nnoremap [unite] <Nop> nmap <Space>u [unite] nnoremap <silent> [unite]c :<C-u>UniteWithCurrentDir -buffer-name=files buffer file_mru bookmark file<CR> nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
ãã®è¨å®ã«ããã<Space>uc
ã<Space>ub
ã§Uniteã®ã³ãã³ããå®è¡ãããã¨ãã§ãã¾ãã
ã¡ãªã¿ã«ãåãã®äºè¡ã¯<Space>u
ãprefixãã¼ã¨ãã¦è¨å®ãã¦ã[unite]
ã§ãã¼ãããã³ã°ããç®æã¯<Space>u
ã§ç½®ãæããã¨ããhackã§ãã
ãã®ããã«å®ç¾©ãã¦ããã¡ãªããã¯ãvimrcä¸è¦ããããªãã¨ããå¹æãããã¾ããã<Space>u
ã¨æã£ãæã«[unite]
ã¨è¡¨ç¤ºããããããprefixãã¼ãæã£ãã¨ãããã¨ãææ¡ã§ããã¨ããå¹æãããã¾ãã
vim hacksã«ã説æãããã®ã§ç¥ããªãã£ãæ¹ã¯ãã¡ããã©ãã
Hack #59: åãããããKey-mappingsãå®ç¾©ãã
ããè¡ãæä½ã«å²ãå½ã¦ã
ä¸ã®ãpluginå¼ã³åºãã«å²ãå½ã¦ããã¨è¿ãã§ããããã¡ãã¯èªåã§ä½ã£ãé¢æ°ãã¡ãã£ã¨ããæä½ããã¼ãããã«å²ãå½ã¦ã¾ãã
ä¾ãã°ä»¥ä¸ã®ããã«helpãå¼ããã¼ããããè¨å®ãããªã©ã§ãã
nnoremap <C-h> :<C-u>help<Space> nnoremap <C-h><C-h> :<C-u>help<Space><C-r><C-w><CR>
使ãã¥ãããã¼ã使ãããããã¼ã«å²ãå½ã¦ã
Vimã§ã¯ããããã®ãã¼ã«è²ã ãªæ©è½ãå²ãå½ã¦ããã¦ãã¾ããã人ã«ãã£ã¦ä½¿ããã¼ã使ããªããã¼ãçµæ§ã¾ã¡ã¾ã¡ã ã¨æãã¾ãã ãã¯ãããªããªä½¿ããï¼ã¨ãã人ãããã¯ããªã«ããç¾å³ããã®ã¨ãã人ã§ã¯ãã使ããã¼ãç°ãªãããã§ãã(ãã¼ã§ãçãããã¯ã使ãã¾ãããããã¯ãããããªä¾¿å©ãªæ©è½ä½¿ããªãã¨ãã£ãããªãã§ããã) ãã®ãã¼ãã使ãã®ã«ãªããæ¼ãã¥ãããã ããªãã¨æã£ãããã¼ãããã³ã°ãèããæããããã¾ããã ä¾ãã°ãèªåã¯ä»¥ä¸ã®ããã«ç½®ãæãã¦ã¾ãã
ã³ãã³ãã©ã¤ã³ã¢ã¼ãã«å
¥ãããã®:ã¨ãf
,t
,F
,T
ãç¹°ãè¿ã;
ãå
¥ãæ¿ãã¦ã¾ãã
;
ã®ããã©ã«ãã®æ©è½ã使ãã¾ãããã³ãã³ãã©ã¤ã³ã¢ã¼ãã«å
¥ãæ¹ãå§åçã«å¤ãã®ã§æ¼ãããã;
ã«ã³ãã³ãã©ã¤ã³ã¢ã¼ãã«å
¥ãæ©è½ãå²ãå½ã¦ã¦ãã¾ãã
nnoremap ; : nnoremap : ;
表示ä¸ã®è¡ç§»å(ã¨ãã£ã¿ã§è¡¨ç¤ºããã¦ããè¡)ã§ããgj
,gk
ã¨ãå®éã®è¡ç§»å(ã¨ãã£ã¿ã®è¡¨ç¤ºè¡ã§ã¯ãªãæ¹è¡ã³ã¼ããæèããå®éã®è¡)ã§ããj
,k
ãå
¥ãæ¿ãã¦ã¾ãã
表示ä¸ã®è¡ç§»åã®æ¹ãç´æçã«ä¾¿å©ã ã¨ããå¤æããæ¼ããããj
,k
ã«å²ãå½ã¦ã¦ãã¾ãã
nnoremap j gj nnoremap k gk nnoremap gj j nnoremap gk k
誤æä½ããã¨å°ããã¼ãç¡å¹åãã
ä¾ãã°ãZZ
(ä¿åãã¦éãã)ã¨ZQ
(ä¿åããéãã)ã¯ã¨ã¦ã便å©ãªæ©è½ãªãã§ããã常ç¨ããã¨ãã¾ã«ãããä¿åãããã£ãã®ã«ééã£ã¦ZQ
ã§éãã¡ãã£ãorzããªãã¦ãã¨ãããã誤ã¿ã¤ãã«ãããªã¹ã¯ãå©ä¾¿æ§ãä¸åãã¾ãã
ãªã®ã§ãããªæãã§ç¡å¹åãã¦ãã¾ãã¨ããã§ãããã
nnoremap ZZ <Nop> nnoremap ZQ <Nop>
<Nop>
ã¯ç©ºãããã§ä½ãããªãã¨ããæå³ã«ãªãã¾ã(:help <nop>
)ã
ä»ã«ç¡å¹ã«ããã¨ããã®ã¯Q
ã§ããQ
ã§exã¢ã¼ãã«å
¥ããã®ã§ãããæå³ããexã¢ã¼ãã«å
¥ã£ã¦ãã¾ããç¹ã«åå¿è
ã¯ã©ããããããªããªã£ã¦:q
ãã¦ãã¾ãæ¹ãããã¨æãã¾ã(èªåããã®ä¸äºº)ã
ä»ã®æ代exã¢ã¼ãã使ãäºãªãã¦ã»ã¨ãã©ãªãã®ã§ã誤ã¿ã¤ãé²æ¢ã§ç¡å¹åãã¾ãã
nnoremap Q <Nop>
:help gq
ãåèã«gq
ã«å²ãå½ã¦ã¦ãããã§ããã
nnoremap Q gq
ã©ã®ãã¼ã«ãã¼ãããã³ã°ãããï¼
ããã¾ã§ã§ãã©ãããæã«ãã¼ããããè¨å®ãããã«ã¤ãã¦ã話ãã¾ããã ã§ã¯ã©ã®ãã¼ã«å²ãå½ã¦ãã®ãããã®ãã«ã¤ãã¦ã話ãã¾ãã
ã¨ãã£ã¦ããæè¦çã«ãããã¸ãã®ãã¼ãè¯ãããã¨ããã®ã¯ãããã§ãããå®éæ¬å½ã«ãããªã®ãæ´çãããã¨ããªãã£ãã®ã§ããã®æ©ä¼ã«æ´çãã¦ã¿ã¾ããã æ´çã®ãã¤ã³ãã¯2ç¹ã
- ãã®ãã¼ã«ããã©ã«ãã§å²ãå½ã¦ããã¦ããæ©è½ã使ããï¼
- ãã®ãã¼ã¯æ¼ãããããï¼
1.ã¯å²ãå½ã¦ããã¦ããæ©è½ã使ããªããã¼ã®ã»ãããã¼ãããã³ã°ã«é©ãã¦ããã2.ã¯æ¼ããããã»ã©ãã¼ãããã³ã°ã«é©ãã¦ããã¨ãããã¨ã§ãã
ä¸è¨2ã¤ã®ãã¤ã³ãã§æ´çãã¦ã¾ã¨ããè³æãgistã«ããã¾ããã ä»åæ´çããã®ã¯normalã¢ã¼ãã ãã§ãã
vimã§ä½¿ããã¼ã®æ©è½ä½¿ç¨é »åº¦ã¨æã¡ãããã®æ´ç
ä¸è¨ãæ´çããçµæ以ä¸ã®ãã¨ããããã¾ããã
ãã¼ãããã³ã°ã«é©ãã¦ãããã¼(ä»åã¯normalã¢ã¼ãã ã)
詳細ã¯gistã®è³æãè¦ã¦ããã ãã¨ãã¦ã normalã¢ã¼ãã§ã¯ç¹ã«ä»¥ä¸ã®ãã¼ããã¼ãããã³ã°ã«é©ãã¦ãããã§ãã
<Space>
,
s
t
m
(prefixã«)
<Space>
ãã¼
<Space>
ã®ããã©ã«ãã®æ©è½ã¯l
ã¨åãã§ããã<Space>
ã¨ãã¦ã»ã¼ä½¿ãæ©ä¼ããªãå²ã«ã¨ã¦ãæ¼ãããããã¼ã§ã(:help <Space>
)ã
<Space>
ã¯ä»ã®ãã¼ã¨åããã¦prefixãã¼ã¨ãã¦ä½¿ããã¨ããããããã¾ãã
ä¸ã§ãä¾ã¨ãã¦ããã¾ãããã以ä¸ã®æ§ãªæãã§ãã
<Space>u
ã§ãplugin uniteã®å°ç¨ã®prefixãã¼ã¨ãã¦ä½¿ã£ã¦ãã¾ãã
nnoremap [unite] <Nop> nmap <Space>u [unite] nnoremap <silent> [unite]c :<C-u>UniteWithCurrentDir -buffer-name=files buffer file_mru bookmark file<CR> nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
,
ãã¼
f
,t
,F
,T
ã§ã¸ã£ã³ãããå¾ã«ãå対æ¹åã«ç¹°ãè¿ãã®ã«ä½¿ããã¼ã§ãã
f
,t
,F
,T
ãå¤ç¨ãã人ã§ããã°ä½¿ãæ©ä¼ããããã¨æãã¾ããã;
ã®é²è¡æ¹åã«ç¹°ãè¿ãæ©è½ã¯ä½¿ãã©ãè¡ãããã¦æ»ãããã¨æããã¨ã¯ã»ã¨ãã©ããã¾ããã
ãªã®ã§èªåã¯æ½°ãã¦ãã¾ã£ã¦ãã¾ãã
<Space>
ã»ã©ã§ã¯ããã¾ããããç¨ã
ã«æ¼ãããããã¼ãªã®ã§ä»ã®ãã¼ã¨åããã¦prefixãã¼ã¨ãã¦ä½¿ãã®ãããããããã¾ããã
以ä¸ã®ããã«ãã¦mapleaderã«è¨å®ããã®ããå§ãã§ãã
let mapleader = "," " ,ã®ããã©ã«ãã®æ©è½ã¯ã\ã§ä½¿ããããã«éé¿ noremap \ ,
ãã®ããã«è¨å®ãã¦ããã¨ãmappingã®é<Leader>
ã¨ãããç®æã,
ã§ç½®ãæããã¾ãã
以ä¸ã®æ§ãªæãã§ãã
nnoremap <Leader>vv :<C-u>VimShell<CR> " ä¸è¨ã¯å®éã«ã¯ãã®ããã«ãã¼ãããã³ã°ããã nnoremap ,vv :<C-u>VimShell<CR>
<Leader>
ã¯èªåã§ãã¼ãããã³ã°ããéã«ã使ãã¾ãããhelpã«ãæ¸ããã¦ããéããpluginã使ããã¨ãæå³ããã¦ããããèªåã§ãã¼ãããã³ã°ããéã¯ã¡ãã£ã¨æ³¨æãå¿
è¦ã§ã(:help mapleader
)ã
s
ãã¼
s
ã®ããã©ã«ãã®æ©è½ã¯ãcl
ã§ä»£ç¨å¯è½ã§ããããã®æ©è½ã®ããã ãã«s
ãã¼ã使ãã®ã¯ã¡ãã£ã¨ãã£ãããªãã§ã(:help s
)ã
ãªã®ã§ä½¿ãããã¼ããªãã¦å°ã£ã¦ããå ´åã¯æãåã£ã¦æ½°ãäºããããããã¾ãã
<Space>
ããæ¼ããããã¨ã¯ãããªãã§ãã(ãã¼ã®ä½ç½®çã«)ãæä¸ã¤ã§ä½¿ããè²´éãªãã¼ãªã®ã§å¤ç¨ããæ©è½ã«å²ãå½ã¦ãã®ãããã§ãã
ãã¡ããprefixã¨ãã¦ä½¿ãã®ãããã¨æãã¾ãã
t
ãã¼
t
ã®ããã©ã«ãã®æ©è½ã¯ãã«ã¼ã½ã«å·¦æ¹åã«åãã£ã¦ãt
ã®å¾ã«å
¥åããæåã¾ã§ã¸ã£ã³ãåºæ¥ãæ©è½ã§ã(:help t
)ã
f
ã¨ä¼¼ã¦ãã¾ãããf
ã¨éãã®ã¯f
ã¯å
¥åããæåã¾ã§ã¸ã£ã³ãããã®ã«å¯¾ãã¦ãt
ã¯å
¥åããæåã®å·¦å´ã®æåã¾ã§ã¸ã£ã³ããããã¨ã§ãã
t
ã®æ©è½ã¯ãªãã¬ã¼ã¿ã¼ã¢ã¼ãã§ä½¿ãæ©ä¼ãå¤ãæ©è½ã§ãããnormalã¢ã¼ãã§ä½¿ãããã¨æããã¨ã¯ã»ã¨ãã©ããã¾ããã
ææªf
ã§é£ãã å¾ã«h
ã§åãäºãåºæ¥ãã®ã§ãæ½°ãã¦ãã¾ã£ã¦ãæ§ããªãã¨æãã¾ãã
t
ãs
ã¨åããããªèãã§å²ãå½ã¦ãã¨ããã¨æãã¾ãã
m
ãã¼
m
ã®ããã©ã«ãã®æ©è½ã¯ããã¼ã«ãè¨å®ãããã¨ã§ãã(:help m
)ãæ大52åã®ãã¼(a-z,A-Z
)ã«å²ãå½ã¦ããã¨ãã§ããããããã¹ã¦ã®ãã¼ã使ã人ã¯ãã£ãã«ãªãã¨æãã¾ãã
ãªã®ã§ãä¾ãã°ãã¼ã«ã«ä½¿ãã®ã¯abcdeãªã©ã¨æ±ºãã¦ããããã以å¤ã®ãã¼ããã¼ãããã³ã°ç¨ã¨ãã¦ä½¿ã£ã¦ãããã¨æãã¾ãã
ãã¼ã«ããã¾ã使ããªã人ã§ããã°ãmm
,mn
,mk
,mj
ãªã©çæã§å
¥åãããããã¼ããã¼ãããã³ã°å¯¾è±¡ã¨ãã¦èãããã¨ããããããã¾ãã
ãã¼ãããã³ã°ã®è¦ãæ¹
ä¸ã§ã¯ãç¹ã«æ¼ããããã«æ³¨ç®ãã¦è©±ããã¾ããããããã ãã ã¨å°ããã¨ãããã¾ãã ãããã³ã°ãããã¼ãå¢ãã¦ãããã¨ã«ãå¿ãã¦ãã¾ãã®ã§ãã
ããã§ãæ¼ãããã以å¤ã«ãå¿ãã«ãã(é£æ³ã®ãããã)ãèæ ®ãã¦ãã¼ãããã³ã°ãããã¨ããããããã¾ãã
ä¾ãã°ãpluginã®æ©è½ãå²ãå½ã¦ããã¼ãããã³ã°ã§ã¯ããã®pluginã®é æåã使ããªã©ã§ãã
ä¸ã§ãä¾ã«ä¸ãã¾ããã(3åç®)ãuniteã®ãã¼ãããã³ã°ã¯è¦ãããããèæ
®ãã¦ã<Space>u
ãprefixã¨ãã¦è¨å®ãã¦ãã¾ãã
ããã«æ©è½ãã¨ã«ããªãã¹ãé£æ³ã§ããããªãã¼ãå²ãå½ã¦ã¦ããã¾ãã
ä¾ãã°ãUnite bufferãªããUniteã®uãbufferã®bãåã£ã¦ã<Space>ub
ãªã©ã¨ãã¾ãã
nnoremap [unite] <Nop> nmap <Space>u [unite] nnoremap <silent> [unite]c :<C-u>UniteWithCurrentDir -buffer-name=files buffer file_mru bookmark file<CR> nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
<Space>
ã¯é¢ä¿ãªããªãï¼ã¨æãããããããã¾ããããããã¯ãpluginã«å²ãå½ã¦ããã¼ã¯<Space>
ã¨æ±ºãã¦ããã°è¦ãããã¾ãã
ç½®ãæããæ¹ãè¯ããã¼
æ´çãã表ãè¦ãã¨ä»ã«ãæ°ã«ãªãç¹ãè¦ãã¦ãã¾ãã ä¾ãã°ããã使ããã¼ãªã®ã«æ¼ãã¥ãããã¼ã§ãã
æåã®æ¹ã§ãã話ãã¾ãããããã使ããã¼ã§æ¼ãã¥ãããã¼ã¯ãå¥ã®ãã¼ã«ãã¼ãããã³ã°ããåè£ã«ãªãã¾ãã
ä¾ãã°ã^
,$
,*
ãªã©ã¯ãã使ãå²ã«ãå
¨ã¦Shiftãä¼´ããã¼ã§ãã(å°æãç²å¼ãã)ãããã«ãã¼ã ãã¸ã·ã§ã³ããè¥å¹²é ãæ¼ãã¥ãããã¼ã§ãã
ãªã®ã§ãç§ã¯ä»¥ä¸ã®ããã«å²ãå½ã¦ã¦ãã¾ãã
noremap <Space>h ^ noremap <Space>l $ nnoremap <Space>/ *
ã¡ãªã¿ã«ä»åæ´çãããã¨ã§ä»¥ä¸ã®ãã¼ããããè¨å®ãããã¨ã«ãã¾ããã%
ãæ¼ãã¥ããã§ãããã
noremap <Space>m %
ã¡ãªã¿ã«ãä¸ã§èª¬æãããpluginã«å²ãå½ã¦ããã¼ã
<Space>
ã¨æ±ºãã¦ããã°ããã®èª¬æã¨çç¾ããã®ã§ã¯ï¼ã¨æã£ãæ¹ã¯ããã©ãã§ãã èªåãã¡ããã¨é ã§æ´çãã¦ãã¼ãããã³ã°ãè¡ãªã£ã¦ããããã§ã¯ãªãã®ã§ããããããã¼ãããã³ã°ãããã¾ãã ã¾ã ãã¾ããã¼ãããã³ã°ãã¦ããªãæ¹ã¯ããªãã¹ãèªåã®ä¸ã§ç´å¾ã§ããããã«æ´çããã¨ããã§ãã
ã¾ã¨ã
以ä¸ããç§ããã¼ãããã³ã°ã§ãã¼ãå²ãå½ã¦ãéã«èãããã¨ã§ãã
大層ãªèãæ¹ã§ããªãã§ãããçããããã¼ãããã³ã°ãèããéã®ä¸å©ã¨ãªãã°å¹¸ãã§ãã
æéãããã°ãèªåã®æ´ç表ãä½ã£ã¦ã¾ã¨ãã¦è¦ããã¨ããããããã¾ãã(ãã£ã¨æ°ããªãã¼ãããã³ã°ã®å¯è½æ§ãåºã¦ããã¨æãã¾ãã)
ãããªèãæ¹ãããããªã©ã®ãæè¦ãããã°ã³ã¡ã³ãããã ããã¨ãããããã§ãã
ãã¨ããã¼ãããã³ã°ã«éãã¾ããããvimã¬ãã«ãä¸ããã®ã§vimrcèªæ¸ä¼ã«åå ãããã¨ããããããã¾ããæ¯é±åææ¥23æãããã£ã¦ã¾ãã
ããã§ã¯Vim Advent Calendar 2012ã®153æ¥ç®ãçµããã¾ãã
ææ¥ã®Vim Advent Calendar 2012ã¯tyruããã§ãã