javascript.vim 2.5 KB

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