javascript.vim 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. " Vim filetype plugin file
  2. " Language: Javascript
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Contributor: Romain Lafourcade <romainlafourcade@gmail.com>
  5. " Last Change: 2024 Jan 14
  6. " 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
  7. if exists("b:did_ftplugin")
  8. finish
  9. endif
  10. let b:did_ftplugin = 1
  11. let s:cpo_save = &cpo
  12. set cpo-=C
  13. " Set 'formatoptions' to break comment lines but not other lines,
  14. " and insert the comment leader when hitting <CR> or using "o".
  15. setlocal formatoptions-=t formatoptions+=croql
  16. " Set completion with CTRL-X CTRL-O to autoloaded function.
  17. if exists('&ofu')
  18. setlocal omnifunc=javascriptcomplete#CompleteJS
  19. endif
  20. " Set 'comments' to format dashed lists in comments.
  21. setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
  22. setlocal commentstring=//\ %s
  23. " Change the :browse e filter to primarily show JavaScript-related files.
  24. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  25. let b:browsefilter =
  26. \ "JavaScript Files (*.js)\t*.js\n"
  27. \ .. "JSX Files (*.jsx)\t*.jsx\n"
  28. \ .. "JavaScript Modules (*.es, *.es6, *.cjs, *.mjs, *.jsm)\t*.es;*.es6;*.cjs;*.mjs;*.jsm\n"
  29. \ .. "Vue Templates (*.vue)\t*.vue\n"
  30. \ .. "JSON Files (*.json)\t*.json\n"
  31. if has("win32")
  32. let b:browsefilter ..= "All Files (*.*)\t*\n"
  33. else
  34. let b:browsefilter ..= "All Files (*)\t*\n"
  35. endif
  36. endif
  37. " The following suffixes should be implied when resolving filenames
  38. setlocal suffixesadd+=.js,.jsx,.es,.es6,.cjs,.mjs,.jsm,.vue,.json
  39. " The following suffixes should have low priority
  40. " .snap jest snapshot
  41. setlocal suffixes+=.snap
  42. " Remove irrelevant part of 'path'.
  43. " User is expected to augment it with contextually-relevant paths
  44. setlocal path-=/usr/include
  45. " Matchit configuration
  46. if exists("loaded_matchit")
  47. let b:match_ignorecase = 0
  48. let b:match_words =
  49. \ '\<do\>:\<while\>,'
  50. \ .. '<\@<=\([^ \t>/]\+\)\%(\s\+[^>]*\%([^/]>\|$\)\|>\|$\):<\@<=/\1>,'
  51. \ .. '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
  52. endif
  53. " Set 'define' to a comprehensive value
  54. let &l:define =
  55. \ '\(^\s*(*async\s\+function\|(*function\)'
  56. \ .. '\|^\s*\(\*\|static\|async\|get\|set\|\i\+\.\)'
  57. \ .. '\|^\s*\(\ze\i\+\)\(([^)]*).*{$\|\s*[:=,]\)'
  58. \ .. '\|^\s*\(export\s\+\|export\s\+default\s\+\)*\(var\|let\|const\|function\|class\)'
  59. \ .. '\|\<as\>'
  60. let b:undo_ftplugin =
  61. \ "setl fo< ofu< com< cms< sua< su< def< pa<"
  62. \ .. "| unlet! b:browsefilter b:match_ignorecase b:match_words"
  63. let &cpo = s:cpo_save
  64. unlet s:cpo_save
  65. " vim: textwidth=78 tabstop=8 shiftwidth=4 softtabstop=4 expandtab