Vim Advent Calendar 2013 110æ¥ç®: Vim script ãããã¼å ¥åãå¼ã³åºã
ãã®è¨äºã¯ Vim Advent Calendar 2013 110æ¥ç®ã®è¨äºã«ãªãã¾ãã
1ã¤é£ãã§ãããããªæ°ããã¾ããæ¸ãããæ¹ãããã°æãã¦ä¸ããã
ãã¦ãä»å㯠Vim script ãããã¼å
¥åãå¼ã³åºãæ¹æ³ã«ã¤ãã¦ç°¡åã«æ¸ãã¾ãã
[:normal {commands} ã使ã]
{commands} ãå®è¡ãã¾ãã
ãã㯠{commands} ããã¼ãã«ã¢ã¼ããããã¼å
¥åããæã¨åãããã«å®è¡ããã¾ãã
" ã«ã¼ã½ã«è¡ã "a ã«ä¿åãã " ! ãä»ããå ´åã¯ããããå±éããªã normal! "add " ç¹æ®ãã¼ãå«ããå ´å㯠execute "\" ãå©ç¨ããå¿ è¦ããã execute "normal! :echo 42\<CR>" " <Plug> ãããã¼ããããå¼ã³åºããã execute "normal \<Plug>(hoge)"
åºæ¬çã«ã¯ãã®ã³ãã³ãã使ç¨ããã¨ããã¨æãã¾ãã
[feedkeys({string} [, {mode}]) ã使ã]
normal ã¨åãããã« {string} ããã¼å
¥åãããæã¨åãããã«å®è¡ãã¾ãã
ãã ããnormal ã¨ã¯éããã®å
¥åã¯å¦çãã¥ã¼ã«å
¥ããããç¾å¨ã®å¦çãçµäºãã¦ããå¼ã³åºããã¾ãã
" {mode} ã "n" ã®å ´åã¯ããããå±éããªã " "m" ã®å ´åã¯ããããå±éããï¼æ¢å®å¤ï¼ call feedkeys("yiw", "n") " ç¹æ®ãã¼ãå«ããå ´åã¯ãnormal ã¨åãããã« \ ã使ç¨ãã call feedkeys(":echo 42\<CR>") function! Hlsearch() " é¢æ°ã®å¼ã³åºãå¾ã«å¦çããã call feedkeys(":set hlsearch\<CR>", "n") endfunction
é¢æ°ãªã©ãå¼ã³åºãããå¾ã«å¦çãè¡ãããå ´åã«å©ç¨ããäºãã§ãã¾ãã
[ãã¾ãï¼å ¥åããããã¼ãã³ãã³ãã©ã¤ã³ã«è¡¨ç¤ºããªã]
execute "normal :let hoge = 12\<CR>"
ãªã©ãå®è¡ããã¨ã³ãã³ãã©ã¤ã³ã«
let hoge = 12
ã¨è¡¨ç¤ºããã¾ãã
ããã表示ãããªãããããå ´åã¯ã
silent execute "normal :let hoge = 12\<CR>"
ã¨ãã風㫠silent ã使ç¨ããäºã§å®ç¾ããäºãã§ãã¾ãã
ã¾ããfeedkeys() ã®å ´åã¯ããå°ã工夫ãå¿ è¦ã§
" å¦çã表示ãããªãããã« <silent> ã§ããããã nnoremap <silent> <Plug>(hoge) :let hoge = 42<CR> " <silent> ã§å®ç¾©ããããããå¼ã³åºã call feedkeys("\<Plug>(hoge)")
ãã®ããã«ä¸åº¦ã