Lai*_*uan 38 vim bash file-type
有时我写脚本没有任何文件扩展名.例如:
#!/usr/bin/env node
console.log('hello world!');
Run Code Online (Sandbox Code Playgroud)
我希望Vim可以从shebang行检测文件类型(例如#!/usr/bin/env node
是javascript
).我该filetype.vim
怎么办?
ib.*_*ib. 31
按照列出的说明:help new-filetype-scripts
,scripts.vim
在用户运行时目录中创建该文件(~/.vim
在类Unix系统上),并在其中编写以下脚本.
if did_filetype()
finish
endif
if getline(1) =~# '^#!.*/bin/env\s\+node\>'
setfiletype javascript
endif
Run Code Online (Sandbox Code Playgroud)
ali*_*iva 10
~/.vim/ftdetect/node.vim
使用此内容创建此文件
fun! s:DetectNode()
if getline(1) == '#!/usr/bin/env node'
set ft=javascript
endif
endfun
autocmd BufNewFile,BufRead * call s:DetectNode()
Run Code Online (Sandbox Code Playgroud)