blob: 455b794cf0366808a43caba1b2376fbde0f54e55 [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
Riley Bruins0a083062024-06-03 20:40:45 +02006" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
Bram Moolenaar1ef15e32006-02-01 21:56:25 +00007
8if exists("b:did_ftplugin")
Bram Moolenaar207f0092020-08-30 17:20:20 +02009 finish
Bram Moolenaar1ef15e32006-02-01 21:56:25 +000010endif
11let b:did_ftplugin = 1
12
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000013let s:cpo_save = &cpo
14set cpo-=C
15
16" Set 'formatoptions' to break comment lines but not other lines,
Bram Moolenaar207f0092020-08-30 17:20:20 +020017" and insert the comment leader when hitting <CR> or using "o".
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000018setlocal formatoptions-=t formatoptions+=croql
19
20" Set completion with CTRL-X CTRL-O to autoloaded function.
Bram Moolenaar1ef15e32006-02-01 21:56:25 +000021if exists('&ofu')
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000022 setlocal omnifunc=javascriptcomplete#CompleteJS
Bram Moolenaar1ef15e32006-02-01 21:56:25 +000023endif
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000024
25" Set 'comments' to format dashed lists in comments.
26setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
27
Riley Bruins0a083062024-06-03 20:40:45 +020028setlocal commentstring=//\ %s
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000029
Bram Moolenaar207f0092020-08-30 17:20:20 +020030" Change the :browse e filter to primarily show JavaScript-related files.
31if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
32 let b:browsefilter =
33 \ "JavaScript Files (*.js)\t*.js\n"
34 \ .. "JSX Files (*.jsx)\t*.jsx\n"
35 \ .. "JavaScript Modules (*.es, *.es6, *.cjs, *.mjs, *.jsm)\t*.es;*.es6;*.cjs;*.mjs;*.jsm\n"
36 \ .. "Vue Templates (*.vue)\t*.vue\n"
37 \ .. "JSON Files (*.json)\t*.json\n"
Doug Kearns93197fd2024-01-14 20:59:02 +010038 if has("win32")
39 let b:browsefilter ..= "All Files (*.*)\t*\n"
40 else
41 let b:browsefilter ..= "All Files (*)\t*\n"
42 endif
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000043endif
Bram Moolenaar207f0092020-08-30 17:20:20 +020044
45" The following suffixes should be implied when resolving filenames
46setlocal suffixesadd+=.js,.jsx,.es,.es6,.cjs,.mjs,.jsm,.vue,.json
47
48" The following suffixes should have low priority
49" .snap jest snapshot
50setlocal suffixes+=.snap
51
52" Remove irrelevant part of 'path'.
53" User is expected to augment it with contextually-relevant paths
54setlocal path-=/usr/include
55
56" Matchit configuration
57if exists("loaded_matchit")
58 let b:match_ignorecase = 0
59 let b:match_words =
60 \ '\<do\>:\<while\>,'
61 \ .. '<\@<=\([^ \t>/]\+\)\%(\s\+[^>]*\%([^/]>\|$\)\|>\|$\):<\@<=/\1>,'
62 \ .. '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
63endif
64
65" Set 'define' to a comprehensive value
66let &l:define =
67 \ '\(^\s*(*async\s\+function\|(*function\)'
68 \ .. '\|^\s*\(\*\|static\|async\|get\|set\|\i\+\.\)'
69 \ .. '\|^\s*\(\ze\i\+\)\(([^)]*).*{$\|\s*[:=,]\)'
70 \ .. '\|^\s*\(export\s\+\|export\s\+default\s\+\)*\(var\|let\|const\|function\|class\)'
71 \ .. '\|\<as\>'
72
73let b:undo_ftplugin =
74 \ "setl fo< ofu< com< cms< sua< su< def< pa<"
75 \ .. "| unlet! b:browsefilter b:match_ignorecase b:match_words"
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000076
77let &cpo = s:cpo_save
78unlet s:cpo_save
Bram Moolenaar207f0092020-08-30 17:20:20 +020079
80" vim: textwidth=78 tabstop=8 shiftwidth=4 softtabstop=4 expandtab