Skip to content

Commit 405df92

Browse files
committed
Set filetype based on node shebang
Recognizes the node shebang line and sets the filetype to javascript. Syntax highlights the shebang as well.
1 parent 2648939 commit 405df92

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ftdetect/javascript.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function! s:DetectJS()
2+
if getline(1) =~# '^#!.*/bin/env\s\+node\>'
3+
setfiletype javascript
4+
endif
5+
endfunction
6+
autocmd BufNewFile,BufRead * call s:DetectJS()

syntax/javascript.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ setlocal iskeyword+=$
2828

2929
syntax sync fromstart
3030

31+
"" syntax coloring for Node.js shebang line
32+
syn match shebang "^#!.*/bin/env\s\+node\>"
33+
hi link shebang Comment
34+
3135
"" JavaScript comments"{{{
3236
syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained
3337
syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo

0 commit comments

Comments
 (0)