vhdl.vim 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. " VHDL filetype plugin
  2. " Language: VHDL
  3. " Maintainer: R.Shankar <shankar.pec?gmail.com>
  4. " Modified By: Gerald Lai <laigera+vim?gmail.com>
  5. " Last Change: 2011 Dec 11
  6. " 2024 Jan 14 by Vim Project (browsefilter)
  7. " 2023 Aug 28 by Vim Project (undo_ftplugin, commentstring)
  8. " Only do this when not done yet for this buffer
  9. if exists("b:did_ftplugin")
  10. finish
  11. endif
  12. " Don't load another plugin for this buffer
  13. let b:did_ftplugin = 1
  14. let s:cpo_save = &cpo
  15. set cpo&vim
  16. " Set 'formatoptions' to break comment lines but not other lines,
  17. " and insert the comment leader when hitting <CR> or using "o".
  18. "setlocal fo-=t fo+=croqlm1
  19. " Set 'comments' to format dashed lists in comments.
  20. "setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
  21. setlocal commentstring=--\ %s
  22. " Format comments to be up to 78 characters long
  23. "setlocal tw=75
  24. let b:undo_ftplugin = "setl cms< "
  25. " Win32 and GTK can filter files in the browse dialog
  26. "if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  27. " if has("win32")
  28. " let b:browsefilter ..= "All Files (*.*)\t*\n"
  29. " else
  30. " let b:browsefilter ..= "All Files (*)\t*\n"
  31. " endif
  32. " let b:undo_ftplugin .= " | unlet! b:browsefilter"
  33. "endif
  34. " Let the matchit plugin know what items can be matched.
  35. if ! exists("b:match_words") && exists("loaded_matchit")
  36. let b:match_ignorecase=1
  37. let s:notend = '\%(\<end\s\+\)\@<!'
  38. let b:match_words =
  39. \ s:notend.'\<if\>:\<elsif\>:\<else\>:\<end\s\+if\>,'.
  40. \ s:notend.'\<case\>:\<when\>:\<end\s\+case\>,'.
  41. \ s:notend.'\<loop\>:\<end\s\+loop\>,'.
  42. \ s:notend.'\<for\>:\<end\s\+for\>,'.
  43. \ s:notend.'\<generate\>:\<end\s\+generate\>,'.
  44. \ s:notend.'\<record\>:\<end\s\+record\>,'.
  45. \ s:notend.'\<units\>:\<end\s\+units\>,'.
  46. \ s:notend.'\<process\>:\<end\s\+process\>,'.
  47. \ s:notend.'\<block\>:\<end\s\+block\>,'.
  48. \ s:notend.'\<function\>:\<end\s\+function\>,'.
  49. \ s:notend.'\<entity\>:\<end\s\+entity\>,'.
  50. \ s:notend.'\<component\>:\<end\s\+component\>,'.
  51. \ s:notend.'\<architecture\>:\<end\s\+architecture\>,'.
  52. \ s:notend.'\<package\>:\<end\s\+package\>,'.
  53. \ s:notend.'\<procedure\>:\<end\s\+procedure\>,'.
  54. \ s:notend.'\<configuration\>:\<end\s\+configuration\>'
  55. let b:undo_ftplugin .= " | unlet! b:match_ignorecase b:match_words"
  56. endif
  57. if !exists("no_plugin_maps") && !exists("no_vhdl_maps")
  58. " count repeat
  59. function! <SID>CountWrapper(cmd)
  60. let i = v:count1
  61. if a:cmd[0] == ":"
  62. while i > 0
  63. execute a:cmd
  64. let i = i - 1
  65. endwhile
  66. else
  67. execute "normal! gv\<Esc>"
  68. execute "normal ".i.a:cmd
  69. let curcol = col(".")
  70. let curline = line(".")
  71. normal! gv
  72. call cursor(curline, curcol)
  73. endif
  74. endfunction
  75. " explore motion
  76. " keywords: "architecture", "block", "configuration", "component", "entity", "function", "package", "procedure", "process", "record", "units"
  77. let b:vhdl_explore = '\%(architecture\|block\|configuration\|component\|entity\|function\|package\|procedure\|process\|record\|units\)'
  78. noremap <buffer><silent>[[ :<C-u>cal <SID>CountWrapper(':cal search("\\%(--.*\\)\\@<!\\%(\\<end\\s\\+\\)\\@<!\\<".b:vhdl_explore."\\>\\c\\<Bar>\\%^","bW")')<CR>
  79. noremap <buffer><silent>]] :<C-u>cal <SID>CountWrapper(':cal search("\\%(--.*\\)\\@<!\\%(\\<end\\s\\+\\)\\@<!\\<".b:vhdl_explore."\\>\\c\\<Bar>\\%$","W")')<CR>
  80. noremap <buffer><silent>[] :<C-u>cal <SID>CountWrapper(':cal search("\\%(--.*\\)\\@<!\\<end\\s\\+".b:vhdl_explore."\\>\\c\\<Bar>\\%^","bW")')<CR>
  81. noremap <buffer><silent>][ :<C-u>cal <SID>CountWrapper(':cal search("\\%(--.*\\)\\@<!\\<end\\s\\+".b:vhdl_explore."\\>\\c\\<Bar>\\%$","W")')<CR>
  82. vnoremap <buffer><silent>[[ :<C-u>cal <SID>CountWrapper('[[')<CR>
  83. vnoremap <buffer><silent>]] :<C-u>cal <SID>CountWrapper(']]')<CR>
  84. vnoremap <buffer><silent>[] :<C-u>cal <SID>CountWrapper('[]')<CR>
  85. vnoremap <buffer><silent>][ :<C-u>cal <SID>CountWrapper('][')<CR>
  86. let b:undo_ftplugin .=
  87. \ " | silent! execute 'nunmap <buffer> [['" .
  88. \ " | silent! execute 'nunmap <buffer> ]]'" .
  89. \ " | silent! execute 'nunmap <buffer> []'" .
  90. \ " | silent! execute 'nunmap <buffer> ]['" .
  91. \ " | silent! execute 'vunmap <buffer> [['" .
  92. \ " | silent! execute 'vunmap <buffer> ]]'" .
  93. \ " | silent! execute 'vunmap <buffer> []'" .
  94. \ " | silent! execute 'vunmap <buffer> ]['"
  95. endif
  96. let &cpo = s:cpo_save
  97. unlet s:cpo_save