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