vim.vim 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. " Vim filetype plugin
  2. " Language: Vim
  3. " Maintainer: Bram Moolenaar <Bram@vim.org>
  4. " Last Change: 2018 Aug 07
  5. " Only do this when not done yet for this buffer
  6. if exists("b:did_ftplugin")
  7. finish
  8. endif
  9. " Don't load another plugin for this buffer
  10. let b:did_ftplugin = 1
  11. let s:cpo_save = &cpo
  12. set cpo-=C
  13. if !exists('*VimFtpluginUndo')
  14. func VimFtpluginUndo()
  15. setl fo< isk< com< tw< commentstring< keywordprg<
  16. if exists('b:did_add_maps')
  17. silent! nunmap <buffer> [[
  18. silent! vunmap <buffer> [[
  19. silent! nunmap <buffer> ]]
  20. silent! vunmap <buffer> ]]
  21. silent! nunmap <buffer> []
  22. silent! vunmap <buffer> []
  23. silent! nunmap <buffer> ][
  24. silent! vunmap <buffer> ][
  25. silent! nunmap <buffer> ]"
  26. silent! vunmap <buffer> ]"
  27. silent! nunmap <buffer> ["
  28. silent! vunmap <buffer> ["
  29. endif
  30. unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps
  31. endfunc
  32. endif
  33. let b:undo_ftplugin = "call VimFtpluginUndo()"
  34. " Set 'formatoptions' to break comment lines but not other lines,
  35. " and insert the comment leader when hitting <CR> or using "o".
  36. setlocal fo-=t fo+=croql
  37. " To allow tag lookup via CTRL-] for autoload functions, '#' must be a
  38. " keyword character. E.g., for netrw#Nread().
  39. setlocal isk+=#
  40. " Use :help to lookup the keyword under the cursor with K.
  41. setlocal keywordprg=:help
  42. " Set 'comments' to format dashed lists in comments
  43. setlocal com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"
  44. " Format comments to be up to 78 characters long
  45. if &tw == 0
  46. setlocal tw=78
  47. endif
  48. " Comments start with a double quote
  49. setlocal commentstring=\"%s
  50. " Prefer Vim help instead of manpages.
  51. setlocal keywordprg=:help
  52. if !exists("no_plugin_maps") && !exists("no_vim_maps")
  53. let b:did_add_maps = 1
  54. " Move around functions.
  55. nnoremap <silent><buffer> [[ m':call search('^\s*fu\%[nction]\>', "bW")<CR>
  56. vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*fu\%[nction]\>', "bW")<CR>
  57. nnoremap <silent><buffer> ]] m':call search('^\s*fu\%[nction]\>', "W")<CR>
  58. vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*fu\%[nction]\>', "W")<CR>
  59. nnoremap <silent><buffer> [] m':call search('^\s*endf\%[unction]\>', "bW")<CR>
  60. vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*endf\%[unction]\>', "bW")<CR>
  61. nnoremap <silent><buffer> ][ m':call search('^\s*endf\%[unction]\>', "W")<CR>
  62. vnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*endf\%[unction]\>', "W")<CR>
  63. " Move around comments
  64. nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
  65. vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
  66. nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
  67. vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
  68. endif
  69. " Let the matchit plugin know what items can be matched.
  70. if exists("loaded_matchit")
  71. let b:match_ignorecase = 0
  72. let b:match_words =
  73. \ '\<fu\%[nction]\>:\<retu\%[rn]\>:\<endf\%[unction]\>,' .
  74. \ '\<\(wh\%[ile]\|for\)\>:\<brea\%[k]\>:\<con\%[tinue]\>:\<end\(w\%[hile]\|fo\%[r]\)\>,' .
  75. \ '\<if\>:\<el\%[seif]\>:\<en\%[dif]\>,' .
  76. \ '\<try\>:\<cat\%[ch]\>:\<fina\%[lly]\>:\<endt\%[ry]\>,' .
  77. \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,'
  78. " Ignore syntax region commands and settings, any 'en*' would clobber
  79. " if-endif.
  80. " - set spl=de,en
  81. " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ …
  82. let b:match_skip = 'synIDattr(synID(line("."),col("."),1),"name")
  83. \ =~? "comment\\|string\\|vimSynReg\\|vimSet"'
  84. endif
  85. let &cpo = s:cpo_save
  86. unlet s:cpo_save
  87. " removed this, because 'cpoptions' is a global option.
  88. " setlocal cpo+=M " makes \%( match \)