vim.vim 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. " Vim filetype plugin
  2. " Language: Vim
  3. " Maintainer: Bram Moolenaar <Bram@vim.org>
  4. " Last Change: 2022 Nov 27
  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&vim
  13. if !exists('*VimFtpluginUndo')
  14. func VimFtpluginUndo()
  15. setl fo< isk< com< tw< commentstring< include< define<
  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. " Comments starts with # in Vim9 script. We have to guess which one to use.
  43. if "\n" .. getline(1, 10)->join("\n") =~# '\n\s*vim9\%[script]\>'
  44. setlocal commentstring=#%s
  45. else
  46. setlocal commentstring=\"%s
  47. endif
  48. " Set 'comments' to format dashed lists in comments, both in Vim9 and legacy
  49. " script.
  50. setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#,sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"
  51. " set 'include' to recognize import commands
  52. setlocal include=\\v^\\s*import\\s*(autoload)?
  53. " set 'define' to recognize export commands
  54. setlocal define=\\v^\\s*export\\s*(def\|const\|var\|final)
  55. " Format comments to be up to 78 characters long
  56. if &tw == 0
  57. setlocal tw=78
  58. endif
  59. if !exists("no_plugin_maps") && !exists("no_vim_maps")
  60. let b:did_add_maps = 1
  61. " Move around functions.
  62. nnoremap <silent><buffer> [[ m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
  63. vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
  64. nnoremap <silent><buffer> ]] m':call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
  65. vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*\(fu\%[nction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
  66. nnoremap <silent><buffer> [] m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
  67. vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "bW")<CR>
  68. nnoremap <silent><buffer> ][ m':call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
  69. vnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*end\(f\%[unction]\\|\(export\s\+\)\?def\)\>', "W")<CR>
  70. " Move around comments
  71. nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
  72. vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
  73. nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
  74. vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
  75. endif
  76. " Let the matchit plugin know what items can be matched.
  77. if exists("loaded_matchit")
  78. let b:match_ignorecase = 0
  79. " "func" can also be used as a type:
  80. " var Ref: func
  81. " or to list functions:
  82. " func name
  83. " require a parenthesis following, then there can be an "endfunc".
  84. let b:match_words =
  85. \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' .
  86. \ '\<\(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\(w\%[hile]\|fo\%[r]\)\>,' .
  87. \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' .
  88. \ '{:},' .
  89. \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' .
  90. \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,'
  91. " Ignore syntax region commands and settings, any 'en*' would clobber
  92. " if-endif.
  93. " - set spl=de,en
  94. " - au! FileType javascript syntax region foldBraces start=/{/ end=/}/ …
  95. let b:match_skip = 'synIDattr(synID(line("."),col("."),1),"name")
  96. \ =~? "comment\\|string\\|vimLetHereDoc\\|vimSynReg\\|vimSet"'
  97. endif
  98. let &cpo = s:cpo_save
  99. unlet s:cpo_save
  100. " removed this, because 'cpoptions' is a global option.
  101. " setlocal cpo+=M " makes \%( match \)