Vim ã§ã³ã³ããã¹ãã«ãã£ã¦ filetype ãèªåçã«åãæãããã©ã°ã¤ã³ãã¤ãã£ã¦ãã
ãã®è¨äºã¯ Vim Advent Calendar 2012 194æ¥ç®ã®è¨äºã«ãªãã¾ãã
ä¾ãã°ãhtml ã§ã¯
<script type="text/javascript"> console.log("Hello, JavaScript") </script>
ä¾ãã°ãmarkdown ã§ã¯
```vim echo "hello, vim" ``` ```ruby echo "hello, ruby" ```
ä¾ãã°ãVim ã§ã¯
python << EOF print map(str, range(1, 10)) print "-".join(map(str, range(1, 10))) for value in range(1, 10): print "mami%d" % value EOF ruby << EOF result = (1..10).map(&:to_s).join("-") p result (1..10).each { |n| p "homu" + n.to_s } EOF
ãã®ããã«ã½ã¼ã¹ã³ã¼ãä¸ã«å¥ã®è¨èªã®ã½ã¼ã¹ã³ã¼ããè¨è¿°ããäºã¯ããã¨æãã¾ãã
ãã®å ´åãåºæ¬çã«ã¯å
ã® filetype ã®ç¶æ
ã§åãè¾¼ãè¨èªã®ã½ã¼ã¹ã³ã¼ããæ¸ããã¨ã«ãªããã§ããããããã㨠filetype ã«ä¾åãããããªå¦çï¼ãã¤ã©ã¤ããã³ã¡ã³ãã¢ã¦ãç³»ã®ãã©ã°ã¤ã³çï¼ã使ç¨ã§ããªãã¦å¤§å¤ä¸ä¾¿ã§ãã
ï¼ä¾ãã° Vim 㧠if_ruby ãæ¸ãå ´å filetype=vim ã®ç¶æ
ã§æ¸ããªããã°ãããªãã
ããã§ããã®åé¡ã解決ããããã«ã«ã¼ã½ã«ä½ç½®ã®ã³ã³ããã¹ãããèªåçã« filetype ãåãæããçºã®ãã©ã°ã¤ã³ãã¤ãã£ã¦ãã¾ãã
ãã®ããã«ã³ã³ããã¹ãã«ãã£ã¦åçã« filetype ãè¨å®ãã¦ã½ã¼ã¹ã³ã¼ããè¨è¿°ããäºãåºæ¥ã¾ãã
[ã¤ã³ã¹ãã¼ã«]
NeoBundle "osyo-manga/vim-precious" " å¿ é ãã©ã°ã¤ã³ NeoBundle "Shougo/context_filetype.vim" " textobj ã使ãããå ´åå¿ è¦ NeoBundle "kana/vim-textobj-user"
[対å¿ã³ã³ããã¹ã]
- c
- masm
- gas
- cpp
- masm
- gas
- d
- eruby
- help
- html
- javascript
- coffee
- css
- int-nyaos
- lua
- nyaos
- perl16
- python
- vim
- vimshell
- xhtml
- javascript
- coffee
- css
- markdown
詳ãã㯠:help context_filetype-support ãåç
§ã
[使ãæ¹]
ç¾å¨ã®ã«ã¼ã½ã«ä½ç½®ã®ã³ã³ããã¹ãã«ãã£ã¦ filetype ãèªåçã«åãæ¿ããã¾ãã
ãããã¯ä¸è¨ã®ãããªè¨å®ã«ãã¦ãã¾ãã
" ã³ããå³ç¦ " quickrun ç¨ã®ãããã³ã° nmap <Space>q <Plug>(precious-quickrun-op) omap ic <Plug>(textobj-precious-i) vmap ic <Plug>(textobj-precious-i) " ã³ã³ããã¹ããåãæ¿ãã£ãå ´åã«å¦çããã㯠" â»ããã«è¼ã£ã¦ããä¾ã¯ãããã®ç°å¢ã®å ´åã®è¨å®ã§ã augroup my-augroup autocmd! " vim ã®ã³ã³ããã¹ãã«åãæ¿ãã£ãæã« " ããã¤ãã®ãããã³ã°ãåé¤ãã " autocmd User PreciousFileTypeLeave_vim iunmap <buffer> <CR> " autocmd User PreciousFileTypeLeave_vim nunmap <buffer> <Leader><Leader>r augroup END " filetype=help 㯠insert æã®ã¿åãæ¿ããããã«è¨å® let g:precious_enable_switch_CursorMoved = { \ "help" : 0 \} function! s:help() augroup my-help autocmd! autocmd InsertEnter <buffer> :PreciousSwitch autocmd InsertLeave <buffer> :PreciousReset augroup END endfunction autocmd FileType help call s:help()
[ã³ã³ããã¹ãã®ç¯å²ã quickrun ãã]
ä¸è¨ã®ããã«ãããã³ã°ãã¦ããã°ã³ã³ããã¹ãã®ç¯å²ãç´ æ©ã quickrun ããäºãåºæ¥ã¾ãã
" quickrun.vim ã¨ã®é£æº " <Space>qic 㧠quickrun.vim ãã " å é¨ã§ã³ã³ããã¹ãã® filetype ã使ç¨ãã¦ããã®ã§ " setfiletype ãè¡ããã¦ããªãã¦ã " ãã®ã³ã³ããã¹ãã® filetype 㧠quickrun ãè¡ããã nmap <Space>q <Plug>(precious-quickrun-op) omap ic <Plug>(textobj-precious-i) vmap ic <Plug>(textobj-precious-i)
ãã㧠markdown çã§è¨äºãæ¸ããªããè¨è¿°ãã¦ããã½ã¼ã¹ã³ã¼ããå®è¡ãã¦åºåãããã®å ´ã§ã³ã¼ãã®åä½ç¢ºèªããäºãåºæ¥ã¾ãã
[èªååæ¿ã®ã¿ã¤ãã³ã°ãå¤æ´ãã]
ããã©ã«ãã®è¨å®ã§ã¯ã«ã¼ã½ã«ã移åãããã³ã« filetype çãåãæ¿ããã®ã§ããã次ã®ããã«è¨å®ãããã¨ã§ insert ã«å
¥ã£ãæã«åãæ¿ããããã«ããäºãåºæ¥ã¾ãã
" ã«ã¼ã½ã«ç§»åæã®èªååãæ¿ããç¡å¹å " ãã®ãªãã·ã§ã³ã¯ filetype ãã¨ã«è¨å®å¯è½ " "*" ã¯å ¨ã¦ã® filetype ã«å½±é¿ãã let g:precious_enable_switch_CursorMoved = { \ "*" : 0 \} let g:precious_enable_switch_CursorMoved_i = { \ "*" : 0 \} " insert ã«å ¥ã£ãæã«ã¹ã¤ããããæããæã«å ã«æ»ã augroup test autocmd! autocmd InsertEnter * :PreciousSwitch autocmd InsertLeave * :PreciousReset augroup END
[注æ]
åããããã¡ã§ filetype ãä½åãåãæ¿ãã¦ããçºã以åã® filetype ã®è¨å®ãå¥ã® filetype ã§ãæ®ã£ã¦ãã¾ãå¯è½æ§ãããã¾ãã
ãã®å ´å㯠undo_ftplugin ã使ç¨ããããprecious.vim ã§ç¨æããã¦ãã autocmd ã«å¦çãããã¯ãã¦è¨å®ãå
ã«æ»ãçã®å·¥å¤«ãå¿
è¦ã«ãªã£ã¦ãã¾ãã
" ä¾ï¼ augroup test autocmd! autocmd FileType vim nnoremap <buffer> <leader><leader>r :so %<CR> " PreciousFileTypeLeave_vim 㯠vim ã®ã³ã³ããã¹ãããæããæã«å¼ã°ãã " ãã®ã¿ã¤ãã³ã°ã§ãããã³ã°ãåé¤ãã¦ãã autocmd User PreciousFileTypeLeave_vim nunmap <buffer> <Leader><Leader>r augroup END
ãã®è¾ºãã¯ããå°ãã©ãã«ããããã¨ããã
ãã¨ãã¤ã©ã¤ãã®èª¤çãç¨ããã
ã¨ãããæãã§ã²ã¨éãããããäºã¯å®è£
ã§ããã®ã§è¨äºã«ãã¦ã¿ã¾ããã
ã¾ã ã¾ã 足ããªãé¨åã¯ããã¨æãã®ã§ä½ã欲ããæ©è½ãããã¾ããã issues ã¾ã§æãã¦ããããã¨å©ããã¾ãï¼(ï½ã»Ïã»Â´)