ãã®è¨äºã¯ Vim Advent Calendar 2014 ã®5æ¥ç®ã®è¨äºã§ãã諸äºæ ã«ããVim Advent Calendar 2014ã§ç©´ã空ãã¦ãã¾ã£ã5æ¥ã®è¨äºããé ãã°ããªãã代æã§æ稿ããã¦ããã ãã¾ãããã®æ稿ã以ã£ã¦ã Vim Advent Calendar 2014 ã¯å ¨ã¦ã®æ¥ç¨ãåã¾ãäºã«ãªãã¾ããå®èµ°ããã§ã¨ããããã¾ããçæ§ããç²ãæ§ã§ããã
2014å¹´ããã¨å ãã¨ãªããå¹´æ«ã®å¿ããã«è¿½ããã¦ããæ¹ããããããã¨ã§ããããåæ¥ã¯å®¶ã®å¤§æé¤ã¨ããæ¹ãå¤ãã®ã§ã¯ãªãã§ããããã
大æé¤â¦å¤§æé¤ã¨è¨ãã°ãvimrcã§ãï¼ï¼ï¼ ããªãã¯vimrcã¯ããããæ¸ãã¦ãã¾ããï¼ Vimããã£ã¨ä¾¿å©ã«ãããããã¾ãããï¼ å ä¸ã¯ç ¥ããã¨ã«ããé·ã使ããã®ã¨åæ§ã«ãæ®æ®µããªãã使ã£ã¦ããvimrcãå®æçã«è¦ãªãããã¨ã§ãããæçããããæ´ã«Vimã«å¯¾ããç解ãæ·±ã¾ãã¾ããããªãã¯ãããªãèªèº«ã®ä½¿ã£ã¦ããvimrcãã©ãã»ã©ç解ãã¦ãã¾ããï¼ãã¾ã«ã¯vimrcã«æ¸ãã¦ããè¨å®ãä¸è¡ãã¤ãã«ããå¼ãã¦ç¢ºããã¦ã¿ãã¨ãæ°ããªçºè¦ããã£ã¦æ¥½ããããããã¾ããã
ãã®è¨äºã§ã¯ãVimã®è¨å®ã§ç¹ã«ä¾¿å©ã ã¨æããã®ããå®å ¨ã«ç¬æã§é¸ãã§åæã«ã©ã³ãã³ã°ãä»ãã¦ãã¾ããVimã®ä¾¿å©ãªãã©ã°ã¤ã³ãç´¹ä»ããè¨äºã¯ããããããã¾ãããæ¬å½ã«Vimã®æ©è½ã«çµã£ã¦ç´¹ä»ããè¨äºã¯å°ãªãã®ã§ãæ¸ãã¦ã¿ã¾ãããå¤ãã®ã¦ã¼ã¶ã¼ãè¨å®ãã¦ããã§ãããæåãªãã®ããåå¿è ã§ã使ã£ã¦ãããããªè¨å®(set numberãªã©)ã¯é¤ãã¾ããã便å©ãªã®ã«ãã¿ããªãè¨å®ãã¦ãªããããªãã®ã§ããã¤ä¸äººã«ããããã§ããè¨å®ããç§ã®ä¸»è¦³ã§é¸ã³ã¾ãããã©ããæ¬å½ã«å°ããªè¨å®ã§ãããVimã§å¿«é©ã«æ®ããä¸ã§ã¨ã¦ã便å©ãªè¨å®ã§ããã©ã³ãã³ã°å½¢å¼ã§æ¸ãã¦ãã¾ãããã©ããã§æ票ããããã§ã¯ãªããå人çã«åæã«é¸ãã§ä¸¦ã¹ãã ãã§ãã®ã§ããäºæ¿ä¸ããã
åªå
ããã§ã¯ãå ã ã®1ä½ããçºè¡¨ãã¾ããè¦äºã«åªåã«è¼ããã®ã¯ãã®è¨å®ã§ãã
nnoremap Y y$
ãããã³ã° Y ããè¡æ«ã¾ã§ã®ã¤ã³ã¯ã«ããè¨å®ã§ãã
æ´å²çãªäºæ
ãããD (è¡æ«ã¾ã§åé¤) ã C (è¡æ«ã¾ã§åé¤ãã¦ã¤ã³ãµã¼ãã¢ã¼ãã«ãã) ã¨ç°ãªã Y (è¡å
¨ä½ãã¤ã³ã¯) ã¯ä¸è²«æ§ã®ãªãåãããã¾ããdd ã«å¯¾ãã Dã cc ã«å¯¾ãã C ã®ããã«ãyy 㨠Y ã§ããä¸è¡ãã¨ãè¡æ«ã¾ã§ãã¨ãã対å¿ãåãããã«ãY ã y$ (è¡æ«ã¾ã§ãã¤ã³ã¯) ã«ããããããã¨ãå¼·ããããããã¾ããDããã使ãã¨ãã人ã¯ããã®è¨å®ã¯ã¨ã¦ããã£ããæ¥ãã¨æãã¾ããY ãªãã¦ä½¿ã£ããã¨ãªããã¨ãã人ã«ãããããããã¦ããã¾ãã
- :help Y
- :help yy
æºåªå
å ã ã®ç¬¬2ä½ã«é¸ã°ããã®ã¯ãã¡ãã
set display=lastline
displayãªãã·ã§ã³ã§ãã
set wrapã¯è¨å®ãã¦ãã¦ãããã®displayãªãã·ã§ã³ãè¨å®ãã¦ããããæ¹ã¯å°ãªãããããã¾ãããä¸ã®ç»åãã覧ä¸ãããããã©ã«ãã§ã¯ãä¸è¡ã®æåæ°ããã¾ãã«å¤ãã¨è¡é ã«ã@ãã¨è¡¨ç¤ºãããã ãã§ããã¡ã¤ã«ã®å
容ãè¦ããªããªã£ã¦ãã¾ãã¾ããããããset display=lastlineã¨ããã ãã§ãä¸è¡ã®æåæ°ãå¤ãã¦ããã¡ãã¨æç»ãããããã«ãªãã®ã§ããããªãããã¾ã«Vimãé·ãè¡ã表示ãã¦ãããªããã¨æã£ããã¨ã®ããæ¹ããããã§ãªãæ¹ããæ¯éset display=lastlineãè¨å®ãã¾ãããã
- :help 'display'
第3ä½
è¦äºãé è³ã«è¼ããã®ã¯ãã¡ãã
set pumheight=10
è£å®ã¡ãã¥ã¼ã®é«ãã§ãã
ãã®ãªãã·ã§ã³ã¯ä½ï¼ã¨ããæ¹ãããããããããã¾ããããã®å¤ã¯ãè£å®ã®ãããã¢ããã¡ãã¥ã¼ã®é«ããè¨å®ãã¾ããããã©ã«ãã¯0ã§ãããã¯(ã¡ãã¥ã¼ãåºããªãã¨ããæå³ã§ã¯ãªã)使ããã ãã®æ大ã®é«ãã使ããã¾ããã¤ã¾ããããã©ã«ãã§ã¯è£å®ã¡ãã¥ã¼ãç»é¢ã®ä¸ã¾ã§å
¨é¨å é ãã¦ãã¾ãã¨ãããã¨ã§ããããã¯ãã£ãè¯ãããã¾ããããç»é¢ããã«ãã«ãã¦ç®ãçããªãã¾ãããæç»ã«ãæéããããã¾ããã ã£ã¦èãã¦ã¿ã¦ãã ãããããIMEã®ã¡ãã¥ã¼ãç»é¢ã®é«ããã£ã±ãã«åè£ãåºãããããããããªãã¯ããããç»é¢ã«ã°ã¼ãã³ãããã¾ããã¨ã§ãããããããªã«åè£ã欲ããã¨æã£ããã¨ã¯ãªãã¯ãã§ãã俺ã®ä½æ¥ãéªéãã¦ããããªã£ã¦ãªããã§ããããè£å®ã¡ãã¥ã¼ã®é«ãã10ãããã«ããã¨ãå¿«é©ãªè£å®ã©ã¤ãã楽ãããã¨æãã¾ãã
- :help pumheight
- :help ins-completion-menu
第4ä½
4ä½ã«è¼ããã®ã¯ãã¡ãã
set showmatch set matchtime=1
ãªãã·ã§ã³ã®showmatchã¨matchtimeã§ãã
ãªãã·ã§ã³showmatchãè¨å®ããã¨ãæ¬å¼§ãå
¥åããæã«ã対å¿ããæ¬å¼§ã«ä¸ç¬ã«ã¼ã½ã«é£ã¶ããã«ãªãã¾ããä¾ãã°ãã( ( ( ( ( ) ) ) ) )ãã¨å
¥åãã¦ã¿ã¦ãã ãããéãæ¬å¼§ãæã¤ã¨ãã«å¯¾å¿ããæ¬å¼§ãåãããããã¨æãã¾ããæ¬å¼§ãæ¸ããã¨ã¯ãããããã¨ã§ãããããã®ãªãã·ã§ã³ã¯ã¨ã¦ã便å©ã§ããæ¢ã«å¤ãã®äººãshowmatchãè¨å®ãã¦ããããããã¾ãããããããè¨å®ãã¦æ¬²ããã®ã¯matchtimeã§ãããªãã·ã§ã³matchtimeã¯ãã«ã¼ã½ã«ãé£ã¶æéã0.1ç§ã®ä½åãã§è¨å®ãã¾ããshowmatchã¯è¨å®ãã¦ãã¦ãmatchtimeã¯è¨å®ãã¦ããªãã¨ãã人ãå¤ãã®ã§ã¯ãªãã§ãããããããã©ã«ãã®matchtimeã¯5ãããªãã¡0.5ç§ã¨ãªã£ã¦ãããæ¬å¼§ãæ¸ããã³ã«ããªãã®0.5ç§ã¯å¥ªããã¦ããã®ã§ããã³ã¼ããæ¸ãã¦ããæã®0.5ç§ã£ã¦æå¤ã¨é·ããã§ããããmatchtime=1ã¨ããã¨æèãé®ããªãã¬ãã«ã«ãªãããããæ¬å¼§ã®å¯¾å¿ãåãã£ã¦ã¨ã¦ãå¿«é©ã«ãªãã¾ãã人ã«ãã£ã¦å¾
ããããã¨æããæéã¯ç°ãªãã¨æãã¾ãã®ã§ããèªèº«ã«ãã£ãå¤ã§è¨å®ãã¦ãã ããã
- :help showmatch
- :help matchtime
第5ä½
ããã¦ã5ä½ã¯ãã¡ãã§ãã
nnoremap + <C-a> nnoremap - <C-x>
æ°åã®ã¤ã³ã¯ãªã¡ã³ãããã¯ãªã¡ã³ãã¸ã®ãããã³ã°ã§ãã
ãããã³ã°ã®<C-a>ã¨ã<C-x>ã¨ããè¦ãã«ããã§ããããã§ãããç§ã¯è¦ãããã + 㨠- ã«ãããã³ã°ãã¦ãã¾ããæ°åãå¢ããã®ã + ã§ãæ¸ããã®ã - ã§ããè¦ããããã§ãããï¼ããã©ã«ãã® + ã - ã¯è¡ã移åãããããã³ã°ã§ããããããã¯j^ãk^ã§ä»£ç¨å¯è½ã§ããããã¾ãç©æ¥µçã«ä½¿ã£ã¦ãã人ã¯å°ãªãã¨æãã¾ããæãåã£ã¦ãã£ã¨é »ç¹ã«ä½¿ãã§ããããæ°åãå¢ãã/æ¸ããã®ã«ä½¿ãã¾ãããããã®æ©è½ã¯ããã¯ãæ©è½ã¨ä¸ç·ã«ä½¿ãã¨ãããåãçºæ®ãã¾ããä»ã«ããã¡ã¤ã«ãã¼ã ãé£çªã«ãªã£ã¦ãããããã¨ãã«ã便å©ã§ãã
- :help CTRL-A
- :help CTRL-X
- :help nrformats
審æ»å¡ç¹å¥è³
ã©ã³ãã³ã°ã¯ããã¾ã§ã§ãããããã便å©ãªã®ã«æãããå ¥è³ã§ããªãã£ãè¨å®ãä¸ã¤ã ãã審æ»å¡ç¹å¥è³ã¨ãã¦ç´¹ä»ãã¾ãã
augroup swapchoice-readonly autocmd! autocmd SwapExists * let v:swapchoice = 'o' augroup END
Vimã®ã¹ã¯ãããã¡ã¤ã«ã¯è¨å®ãã¦ãã¾ããï¼ã¹ã¯ãããã¡ã¤ã«ã¯ä¾¿å©ãªã®ã§è¨å®ãã¾ããããã¹ã¯ãããã¡ã¤ã«ãè¨å®ãããªãã·ã§ã³ã¯swapfileã¨directoryã§ããããããè¨å®ãã¾ãã¨ãããã¤ã端æ«ãéãã¦ãã¦èª¤ã£ã¦åããã¡ã¤ã«ãéããæã«æ°ãã¤ããã¨ãã§ãã¾ãã詳ããã¯ãã«ããã¡ã¤ã«(:help swapfileã:help directory)ãåç
§ãã¦ä¸ããã
ã¨ãããã¹ã¯ãããã¡ã¤ã«ãè¨å®ãã¦ãããªããããã¹ã¯ãããã¡ã¤ã«ãè¦ã¤ãã£ããã©ã©ãããï¼ãã¨ããã¡ãã»ã¼ã¸ãããããã¨æãããã¨ãããã¾ããããããæã«ä¸ã®è¨å®ã便å©ã§ããã¤ã¾ããã¹ã¯ãããããã¨ãã¯å¸¸ã«Read-Onlyã§éãè¨å®ã§ãããããã¦ããã°ããã¡ãã¡ããããã¡ãã»ã¼ã¸ãåºãªããªãã¾ããããããã¹ã¯ãããã¡ã¤ã«ããããã¨ãåããã¾ããã¨ã¦ã便å©ãªã®ã§ãããã¹ã¯ãããã¡ã¤ã«ã®ä½¿ãæ¹ã¯äººã«ãã£ã¦éãã¾ãããããããã¹ã¯ãããã¡ã¤ã«ãå«ãã§ç¡å¹ã«ãã¦ããã¨ããæ¹ãããã£ãããã¾ãã®ã§ãæãããã©ã³ã¯å¤ã¨ãªã£ã¦ãã¾ãã¾ãããä¸è¨ã®è¨å®ããã¦ããã¦ãã£ã±ãã¹ã¯ããã®ã¡ãã»ã¼ã¸ãè¦ããã¨ããæã¯ã:noa e [filename] ã®ããã« :noa(utocmd)ã³ãã³ãã使ãã¾ããã¾ããRead-Onlyãªãã¡ã¤ã«ãç·¨éããå¾ã«ç¡çããæ¸ãè¾¼ãã«ã¯:w!ã使ãã¾ãã
- :help swapchoice
- :help SwapExists
- :help swapfile
- :help directory
- :help swap
ã¾ã¨ã
以ä¸ãç§ã®ç¬æã§é¸ãã ãçããããã¾ãè¨å®ããã¦ããªãã§ãããVimã®ä¾¿å©ãªåºæ¬è¨å®ã©ã³ãã³ã°ã§ããããããã§ããããããã¯ä¾¿å©ãããªè¨å®ã ï¼ã¨ãããã®ãé¸ãã§è¨å®ãã¦ãã ãããVimã«ã¯300以ä¸ãã®ãªãã·ã§ã³ãããããããããã¨ãè¨å®ã§ããããã«ãªã£ã¦ãã¾ããVimã使ã£ã¦ãã¦ä½ããä¸ä¾¿ã ãªãã¨æã£ããã詳ãã人ã«èãã¦ã¿ã¾ããããå¿ ãä½ãçããè¿ã£ã¦ããã¨æãã¾ããé©å½ã«ãVimã£ã¦ããããããããæãä¸ä¾¿ã ãããã¨Twitterã«æ稿ãããã¨ãããããããã«è§£æ±ºããã¨æãã¾ããã¾ããvim-jp – Lingrã«æ稿ãã¦ããã ããã¨ãå¿åªããVimãã¹ã¿ã¼ã®çæ§ãä¸å¯§ã«æãã¦ãããã¨æãã¾ããæ¥ããããããã«ãVimã«å¯¾ããçåãã¶ã¤ãã¦ã¿ã¦ãã ããã
ãã®è¨äºããã¡ã¾ã㦠Vim Advent Calendar 2014 ã¯å®èµ°ã¨ãªãã¾ããé¢ä¿è ã®çæ§ãæ¬å½ã«ãç²ãæ§ã§ãããä»å¹´ãæ§ã ãªè¦³ç¹ããVimã®è¨äºãèªãã¦æ¥½ããã£ãã¨æãã¾ããåæ©çãªå 容ãä¸å¯§ã«è¨è¿°ããè¨äºãããä¸äººåãã®ä¾¿å©ãªãã©ã°ã¤ã³ã®ç´¹ä»è¨äºãããã¦Vimèªä½ã®åä½ã«é¢ããé«åº¦ãªå 容ã¾ã§ãå¹ åºã層ã®æ¹ã«æ¥½ããã§ããã ããAdvent Calendarã§ç´ æµã ãªã¨æãã¾ãããé¨å±ã®å¤§æé¤ãçµããã¾ããããæ¹ã㦠Vim Advent Calendar 2014 ã®è¨äºãè¦ã¦åãã®ã楽ããããããã¾ãããå¹´ã®ç¬ã¯ã¾ãã¾ãå¯ããå³ãããªã£ã¦åãã¾ãããä½ã«æ°ãä»ãã¦ãè¯ãå¹´ããéããä¸ããã