abaqus.vim 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. " Vim filetype plugin file
  2. " Language: Abaqus finite element input file (www.abaqus.com)
  3. " Maintainer: Carl Osterwisch <costerwi@gmail.com>
  4. " Last Change: 2022 Oct 08
  5. " 2024 Jan 14 by Vim Project (browsefilter)
  6. " 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
  7. " Only do this when not done yet for this buffer
  8. if exists("b:did_ftplugin") | finish | endif
  9. " Don't load another plugin for this buffer
  10. let b:did_ftplugin = 1
  11. " Save the compatibility options and temporarily switch to vim defaults
  12. let s:cpo_save = &cpoptions
  13. set cpoptions&vim
  14. " Set the format of the include file specification for Abaqus
  15. " Used in :check gf ^wf [i and other commands
  16. setlocal include=\\<\\cINPUT\\s*=
  17. " Remove characters up to the first = when evaluating filenames
  18. setlocal includeexpr=substitute(v:fname,'.\\{-}=','','')
  19. " Remove comma from valid filename characters since it is used to
  20. " separate keyword parameters
  21. setlocal isfname-=,
  22. " Define format of comment lines (see 'formatoptions' for uses)
  23. setlocal comments=:**
  24. setlocal commentstring=**\ %s
  25. " Definitions start with a * and assign a NAME, NSET, or ELSET
  26. " Used in [d ^wd and other commands
  27. setlocal define=^\\*\\a.*\\c\\(NAME\\\|NSET\\\|ELSET\\)\\s*=
  28. " Abaqus keywords and identifiers may include a - character
  29. setlocal iskeyword+=-
  30. let b:undo_ftplugin = "setlocal include< includeexpr< isfname<"
  31. \ . " comments< commentstring< define< iskeyword<"
  32. if has("folding")
  33. " Fold all lines that do not begin with *
  34. setlocal foldexpr=getline(v:lnum)[0]!=\"\*\"
  35. setlocal foldmethod=expr
  36. let b:undo_ftplugin .= " foldexpr< foldmethod<"
  37. endif
  38. " Set the file browse filter (currently only supported under Win32 gui)
  39. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  40. let b:browsefilter = "Abaqus Input Files (*.inp *.inc)\t*.inp;*.inc\n" .
  41. \ "Abaqus Results (*.dat)\t*.dat\n" .
  42. \ "Abaqus Messages (*.pre, *.msg, *.sta)\t*.pre;*.msg;*.sta\n"
  43. if has("win32")
  44. let b:browsefilter .= "All Files (*.*)\t*\n"
  45. else
  46. let b:browsefilter .= "All Files (*)\t*\n"
  47. endif
  48. let b:undo_ftplugin .= "|unlet! b:browsefilter"
  49. endif
  50. " Define patterns for the matchit plugin
  51. if exists("loaded_matchit") && !exists("b:match_words")
  52. let b:match_ignorecase = 1
  53. let b:match_words =
  54. \ '\*part:\*end\s*part,' .
  55. \ '\*assembly:\*end\s*assembly,' .
  56. \ '\*instance:\*end\s*instance,' .
  57. \ '\*step:\*end\s*step'
  58. let b:undo_ftplugin .= "|unlet! b:match_ignorecase b:match_words"
  59. endif
  60. if !exists("no_plugin_maps") && !exists("no_abaqus_maps")
  61. " Map [[ and ]] keys to move [count] keywords backward or forward
  62. nnoremap <silent><buffer> ]] :call <SID>Abaqus_NextKeyword(1)<CR>
  63. nnoremap <silent><buffer> [[ :call <SID>Abaqus_NextKeyword(-1)<CR>
  64. function! <SID>Abaqus_NextKeyword(direction)
  65. .mark '
  66. if a:direction < 0
  67. let flags = 'b'
  68. else
  69. let flags = ''
  70. endif
  71. let l:count = abs(a:direction) * v:count1
  72. while l:count > 0 && search("^\\*\\a", flags)
  73. let l:count -= 1
  74. endwhile
  75. endfunction
  76. " Map \\ to toggle commenting of the current line or range
  77. noremap <silent><buffer> <LocalLeader><LocalLeader>
  78. \ :call <SID>Abaqus_ToggleComment()<CR>j
  79. function! <SID>Abaqus_ToggleComment() range
  80. if strpart(getline(a:firstline), 0, 2) == "**"
  81. " Un-comment all lines in range
  82. silent execute a:firstline . ',' . a:lastline . 's/^\*\*//'
  83. else
  84. " Comment all lines in range
  85. silent execute a:firstline . ',' . a:lastline . 's/^/**/'
  86. endif
  87. endfunction
  88. " Map \s to swap first two comma separated fields
  89. noremap <silent><buffer> <LocalLeader>s :call <SID>Abaqus_Swap()<CR>
  90. function! <SID>Abaqus_Swap() range
  91. silent execute a:firstline . ',' . a:lastline . 's/\([^*,]*\),\([^,]*\)/\2,\1/'
  92. endfunction
  93. let b:undo_ftplugin .= "|unmap <buffer> [[|unmap <buffer> ]]"
  94. \ . "|unmap <buffer> <LocalLeader><LocalLeader>"
  95. \ . "|unmap <buffer> <LocalLeader>s"
  96. endif
  97. " Undo must be done in nocompatible mode for <LocalLeader>.
  98. let b:undo_ftplugin = "let b:cpo_save = &cpoptions|"
  99. \ . "set cpoptions&vim|"
  100. \ . b:undo_ftplugin
  101. \ . "|let &cpoptions = b:cpo_save"
  102. \ . "|unlet b:cpo_save"
  103. " Restore saved compatibility options
  104. let &cpoptions = s:cpo_save
  105. unlet s:cpo_save