sh.vim 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. if exists("b:did_ftplugin")
  10. finish
  11. endif
  12. let b:did_ftplugin = 1
  13. let s:save_cpo = &cpo
  14. set cpo-=C
  15. setlocal comments=b:#
  16. setlocal commentstring=#\ %s
  17. setlocal formatoptions-=t formatoptions+=croql
  18. let b:undo_ftplugin = "setl com< cms< fo<"
  19. " Shell: thanks to Johannes Zellner
  20. if exists("loaded_matchit") && !exists("b:match_words")
  21. let b:match_ignorecase = 0
  22. let s:sol = '\%(;\s*\|^\s*\)\@<=' " start of line
  23. let b:match_words =
  24. \ s:sol .. 'if\>:' .. s:sol.'elif\>:' .. s:sol.'else\>:' .. s:sol .. 'fi\>,' ..
  25. \ s:sol .. '\%(for\|while\)\>:' .. s:sol .. 'done\>,' ..
  26. \ s:sol .. 'case\>:' .. s:sol .. 'esac\>'
  27. unlet s:sol
  28. let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words"
  29. endif
  30. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  31. let b:browsefilter = "Bourne Shell Scripts (*.sh)\t*.sh\n" ..
  32. \ "Korn Shell Scripts (*.ksh)\t*.ksh\n" ..
  33. \ "Bash Shell Scripts (*.bash)\t*.bash\n"
  34. if has("win32")
  35. let b:browsefilter ..= "All Files (*.*)\t*\n"
  36. else
  37. let b:browsefilter ..= "All Files (*)\t*\n"
  38. endif
  39. let b:undo_ftplugin ..= " | unlet! b:browsefilter"
  40. endif
  41. let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0))
  42. let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0))
  43. let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornshell", 0))
  44. if s:is_bash
  45. if exists(':terminal') == 2
  46. command! -buffer -nargs=1 ShKeywordPrg silent exe ':term bash -c "help "<args>" 2>/dev/null || man "<args>""'
  47. else
  48. command! -buffer -nargs=1 ShKeywordPrg echo system('bash -c "help <args>" 2>/dev/null || MANPAGER= man "<args>"')
  49. endif
  50. setlocal keywordprg=:ShKeywordPrg
  51. let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer ShKeywordPrg"
  52. endif
  53. if (s:is_sh || s:is_bash || s:is_kornshell) && executable('shellcheck')
  54. if !exists('current_compiler')
  55. compiler shellcheck
  56. let b:undo_ftplugin ..= ' | compiler make'
  57. endif
  58. elseif s:is_bash
  59. if !exists('current_compiler')
  60. compiler bash
  61. let b:undo_ftplugin ..= ' | compiler make'
  62. endif
  63. endif
  64. let &cpo = s:save_cpo
  65. unlet s:save_cpo s:is_sh s:is_bash s:is_kornshell
  66. " vim: nowrap sw=2 sts=2 ts=8 noet: