sh.vim (2683B)
1 " Vim filetype plugin file 2 " Language: sh 3 " Maintainer: Doug Kearns <dougkearns@gmail.com> 4 " Previous Maintainer: Dan Sharp 5 " Contributor: Enno Nagel <ennonagel+vim@gmail.com> 6 " Eisuke Kawashima 7 " Last Change: 2024 Sep 19 by Vim Project (compiler shellcheck) 8 " 2024 Dec 29 by Vim Project (improve setting shellcheck compiler) 9 " 2025 Mar 09 by Vim Project (set b:match_skip) 10 " 2025 Jul 22 by phanium (use :hor term #17822) 11 12 if exists("b:did_ftplugin") 13 finish 14 endif 15 let b:did_ftplugin = 1 16 17 let s:save_cpo = &cpo 18 set cpo-=C 19 20 setlocal comments=b:# 21 setlocal commentstring=#\ %s 22 setlocal formatoptions-=t formatoptions+=croql 23 24 let b:undo_ftplugin = "setl com< cms< fo<" 25 26 " Shell: thanks to Johannes Zellner 27 if exists("loaded_matchit") && !exists("b:match_words") 28 let b:match_ignorecase = 0 29 let s:sol = '\%(;\s*\|^\s*\)\@<=' " start of line 30 let b:match_words = 31 \ s:sol .. 'if\>:' .. s:sol.'elif\>:' .. s:sol.'else\>:' .. s:sol .. 'fi\>,' .. 32 \ s:sol .. '\%(for\|while\)\>:' .. s:sol .. 'done\>,' .. 33 \ s:sol .. 'case\>:' .. s:sol .. 'esac\>' 34 unlet s:sol 35 let b:match_skip = "synIDattr(synID(line('.'),col('.'),0),'name') =~ 'shSnglCase'" 36 let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:match_skip" 37 endif 38 39 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") 40 let b:browsefilter = "Bourne Shell Scripts (*.sh)\t*.sh\n" .. 41 \ "Korn Shell Scripts (*.ksh)\t*.ksh\n" .. 42 \ "Bash Shell Scripts (*.bash)\t*.bash\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 51 let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0)) 52 let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0)) 53 let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornshell", 0)) 54 55 if s:is_bash 56 if exists(':terminal') == 2 57 command! -buffer -nargs=1 ShKeywordPrg silent exe ':hor term bash -c "help "<args>" 2>/dev/null || man "<args>""' 58 else 59 command! -buffer -nargs=1 ShKeywordPrg echo system('bash -c "help <args>" 2>/dev/null || MANPAGER= man "<args>"') 60 endif 61 setlocal keywordprg=:ShKeywordPrg 62 let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer ShKeywordPrg" 63 endif 64 65 if (s:is_sh || s:is_bash || s:is_kornshell) && executable('shellcheck') 66 if !exists('current_compiler') 67 compiler shellcheck 68 let b:undo_ftplugin ..= ' | compiler make' 69 endif 70 elseif s:is_bash 71 if !exists('current_compiler') 72 compiler bash 73 let b:undo_ftplugin ..= ' | compiler make' 74 endif 75 endif 76 77 let &cpo = s:save_cpo 78 unlet s:save_cpo s:is_sh s:is_bash s:is_kornshell 79 80 " vim: nowrap sw=2 sts=2 ts=8 noet: