Vim recognizes as javascript

I would like for any file starting with to #!/usr/bin/env nodebe recognized as JavaScript.

I know that Vim does this with other languages ​​like BASH, so there must be a way to do this.

Thank!

+5
source share
2 answers

Add the following code snippet to your .vimrc or other file and enter it in .vimrc:

if did_filetype()
  finish
endif
if getline(1) =~ '#!/usr/bin/env node'
  setfiletype javascript                                                      
endif

It just sets the file type in js when the first line of file matches '#! / Usr / bin / env node' is pretty much explanatory. This is also described in the file type help: check file: filetype

+2
source

node whereis node comamnd. #!/path/to/node. , vim script /path/to/node .

+1

All Articles