vb.vim 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. " Vim filetype plugin file
  2. " Language: Visual Basic (ft=vb)
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Previous Maintainer: Johannes Zellner <johannes@zellner.org>
  5. " Last Change: 2021 Nov 17
  6. if exists("b:did_ftplugin")
  7. finish
  8. endif
  9. let b:did_ftplugin = 1
  10. let s:cpo_save = &cpo
  11. set cpo&vim
  12. setlocal comments=sr:'\ -,mb:'\ \ ,el:'\ \ ,:'
  13. setlocal commentstring='\ %s
  14. setlocal formatoptions-=t formatoptions+=croql
  15. let b:undo_ftplugin = "setlocal com< cms< fo<"
  16. " we need this wrapper, as call doesn't allow a count
  17. function! s:VbSearch(pattern, flags)
  18. let cnt = v:count1
  19. while cnt > 0
  20. call search(a:pattern, a:flags)
  21. let cnt = cnt - 1
  22. endwhile
  23. endfunction
  24. if !exists("no_plugin_maps") && !exists("no_vb_maps")
  25. nnoremap <buffer> <silent> [[ <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sbW')<CR>
  26. vnoremap <buffer> <silent> [[ <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sbW')<CR>
  27. nnoremap <buffer> <silent> ]] <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sW')<CR>
  28. vnoremap <buffer> <silent> ]] <Cmd>call <SID>VbSearch('^\s*\%(\%(private\<Bar>public\)\s\+\)\=\%(function\<Bar>sub\)', 'sW')<CR>
  29. nnoremap <buffer> <silent> [] <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sbW')<CR>
  30. vnoremap <buffer> <silent> [] <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sbW')<CR>
  31. nnoremap <buffer> <silent> ][ <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sW')<CR>
  32. vnoremap <buffer> <silent> ][ <Cmd>call <SID>VbSearch('^\s*end\s\+\%(function\<Bar>sub\)', 'sW')<CR>
  33. let b:undo_ftplugin .= " | sil! exe 'nunmap <buffer> [[' | sil! exe 'vunmap <buffer> [['" .
  34. \ " | sil! exe 'nunmap <buffer> ]]' | sil! exe 'vunmap <buffer> ]]'" .
  35. \ " | sil! exe 'nunmap <buffer> []' | sil! exe 'vunmap <buffer> []'" .
  36. \ " | sil! exe 'nunmap <buffer> ][' | sil! exe 'vunmap <buffer> ]['"
  37. endif
  38. " TODO: line start anchors are almost certainly overly restrictive - allow
  39. " after statement separators. Even in QuickBasic only block IF statements
  40. " were required to be at the start of a line.
  41. if exists("loaded_matchit") && !exists("b:match_words")
  42. let b:match_ignorecase = 1
  43. let b:match_words =
  44. \ '\%(^\s*\)\@<=\<if\>.*\<then\>\s*\%($\|''\):\%(^\s*\)\@<=\<else\>:\%(^\s*\)\@<=\<elseif\>:\%(^\s*\)\@<=\<end\>\s\+\<if\>,' .
  45. \ '\%(^\s*\)\@<=\<for\>:\%(^\s*\)\@<=\<next\>,' .
  46. \ '\%(^\s*\)\@<=\<while\>:\%(^\s*\)\@<=\<wend\>,' .
  47. \ '\%(^\s*\)\@<=\<do\>:\%(^\s*\)\@<=\<loop\>\s\+\<while\>,' .
  48. \ '\%(^\s*\)\@<=\<select\>\s\+\<case\>:\%(^\s*\)\@<=\<case\>:\%(^\s*\)\@<=\<end\>\s\+\<select\>,' .
  49. \ '\%(^\s*\)\@<=\<enum\>:\%(^\s*\)\@<=\<end\>\s\<enum\>,' .
  50. \ '\%(^\s*\)\@<=\<with\>:\%(^\s*\)\@<=\<end\>\s\<with\>,' .
  51. \ '\%(^\s*\)\@<=\%(\<\%(private\|public\)\>\s\+\)\=\<function\>\s\+\([^ \t(]\+\):\%(^\s*\)\@<=\<\1\>\s*=:\%(^\s*\)\@<=\<end\>\s\+\<function\>,' .
  52. \ '\%(^\s*\)\@<=\%(\<\%(private\|public\)\>\s\+\)\=\<sub\>\s\+:\%(^\s*\)\@<=\<end\>\s\+\<sub\>'
  53. let b:undo_ftplugin .= " | unlet! b:match_words b:match_ignorecase"
  54. endif
  55. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  56. let b:browsefilter = "Visual Basic Source Files (*.bas)\t*.bas\n" .
  57. \ "Visual Basic Form Files (*.frm)\t*.frm\n" .
  58. \ "All Files (*.*)\t*.*\n"
  59. let b:undo_ftplugin .= " | unlet! b:browsefilter"
  60. endif
  61. let &cpo = s:cpo_save
  62. unlet s:cpo_save