javascript.vim 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. 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. if has("win32")
  31. let b:browsefilter ..= "All Files (*.*)\t*\n"
  32. else
  33. let b:browsefilter ..= "All Files (*)\t*\n"
  34. endif
  35. endif
  36. " The following suffixes should be implied when resolving filenames
  37. setlocal suffixesadd+=.js,.jsx,.es,.es6,.cjs,.mjs,.jsm,.vue,.json
  38. " The following suffixes should have low priority
  39. " .snap jest snapshot
  40. setlocal suffixes+=.snap
  41. " Remove irrelevant part of 'path'.
  42. " User is expected to augment it with contextually-relevant paths
  43. setlocal path-=/usr/include
  44. " Matchit configuration
  45. if exists("loaded_matchit")
  46. let b:match_ignorecase = 0
  47. let b:match_words =
  48. \ '\<do\>:\<while\>,'
  49. \ .. '<\@<=\([^ \t>/]\+\)\%(\s\+[^>]*\%([^/]>\|$\)\|>\|$\):<\@<=/\1>,'
  50. \ .. '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
  51. endif
  52. " Set 'define' to a comprehensive value
  53. let &l:define =
  54. \ '\(^\s*(*async\s\+function\|(*function\)'
  55. \ .. '\|^\s*\(\*\|static\|async\|get\|set\|\i\+\.\)'
  56. \ .. '\|^\s*\(\ze\i\+\)\(([^)]*).*{$\|\s*[:=,]\)'
  57. \ .. '\|^\s*\(export\s\+\|export\s\+default\s\+\)*\(var\|let\|const\|function\|class\)'
  58. \ .. '\|\<as\>'
  59. let b:undo_ftplugin =
  60. \ "setl fo< ofu< com< cms< sua< su< def< pa<"
  61. \ .. "| unlet! b:browsefilter b:match_ignorecase b:match_words"
  62. let &cpo = s:cpo_save
  63. unlet s:cpo_save
  64. " vim: textwidth=78 tabstop=8 shiftwidth=4 softtabstop=4 expandtab