vim.vim 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. " Vim filetype plugin
  2. " Language: Vim
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Last Change: 2024 Apr 13
  5. " 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
  6. " Former Maintainer: Bram Moolenaar <Bram@vim.org>
  7. " Only do this when not done yet for this buffer
  8. if exists("b:did_ftplugin")
  9. finish
  10. endif
  11. " Don't load another plugin for this buffer
  12. let b:did_ftplugin = 1
  13. let s:cpo_save = &cpo
  14. set cpo&vim
  15. if !exists('*VimFtpluginUndo')
  16. func VimFtpluginUndo()
  17. setl fo< isk< com< tw< commentstring< keywordprg<
  18. if exists('b:did_add_maps')
  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. silent! nunmap <buffer> ["
  30. silent! vunmap <buffer> ["
  31. endif
  32. unlet! b:match_ignorecase b:match_words b:match_skip b:did_add_maps
  33. endfunc
  34. endif
  35. let b:undo_ftplugin = "call VimFtpluginUndo()"
  36. " Set 'formatoptions' to break comment lines but not other lines,
  37. " and insert the comment leader when hitting <CR> or using "o".
  38. setlocal fo-=t fo+=croql
  39. " To allow tag lookup via CTRL-] for autoload functions, '#' must be a
  40. " keyword character. E.g., for netrw#Nread().
  41. setlocal isk+=#
  42. " Use :help to lookup the keyword under the cursor with K.
  43. setlocal keywordprg=:help
  44. " Comments starts with # in Vim9 script. We have to guess which one to use.
  45. if "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>'
  46. setlocal commentstring=#\ %s
  47. else
  48. setlocal commentstring=\"%s
  49. endif
  50. " Set 'comments' to format dashed lists in comments, both in Vim9 and legacy
  51. " script.
  52. setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:#,sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"\\\ ,:\"
  53. " Format comments to be up to 78 characters long
  54. if &tw == 0
  55. setlocal tw=78
  56. endif
  57. if !exists("no_plugin_maps") && !exists("no_vim_maps")
  58. let b:did_add_maps = 1
  59. " Move around functions.
  60. nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR>
  61. vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "bW")<CR>
  62. nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR>
  63. vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|def\)\>', "W")<CR>
  64. nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR>
  65. vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "bW")<CR>
  66. nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR>
  67. vnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|def\)\>', "W")<CR>
  68. " Move around comments
  69. nnoremap <silent><buffer> ]" :call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
  70. vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\@<!\%(^\s*"\)', "W")<CR>
  71. nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
  72. vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
  73. endif
  74. " Let the matchit plugin know what items can be matched.
  75. if exists("loaded_matchit")
  76. let b:match_ignorecase = 0
  77. " "func" can also be used as a type:
  78. " var Ref: func
  79. " or to list functions:
  80. " func name
  81. " require a parenthesis following, then there can be an "endfunc".
  82. let b:match_words =
  83. \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' ..
  84. \ '\<\%(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\%(w\%[hile]\|fo\%[r]\)\>,' ..
  85. \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' ..
  86. \ '{:},' ..
  87. \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' ..
  88. \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' ..
  89. \ '\<class\>:\<endclass\>,' ..
  90. \ '\<inte\%[rface]\>:\<endinterface\>,' ..
  91. \ '\<enu\%[m]\>:\<endenum\>,'
  92. " Ignore syntax region commands and settings, any 'en*' would clobber
  93. " if-endif.
  94. " - set spl=de,en
  95. " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ …
  96. " Also ignore here-doc and dictionary keys (vimVar).
  97. let b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name")
  98. \ =~? "comment\\|string\\|vimSynReg\\|vimSet\\|vimLetHereDoc\\|vimVar"'
  99. endif
  100. let &cpo = s:cpo_save
  101. unlet s:cpo_save
  102. " removed this, because 'cpoptions' is a global option.
  103. " setlocal cpo+=M " makes \%( match \)