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