如何使Vim从shebang行检测文件类型? [英] How to make Vim detect filetype from the shebang line?
本文介绍了如何使Vim从shebang行检测文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有时候我写的脚本没有任何文件扩展名.例如:
Sometimes I write scripts without any filename extension. For example:
#!/usr/bin/env node
console.log('hello world!');
我希望Vim可以从shebang行中检测文件类型(例如#!/usr/bin/env node
是javascript
).我应该在filetype.vim
中放入什么?
I hope that Vim can detect the filetype from the shebang line (e.g. #!/usr/bin/env node
is javascript
). What should I put into filetype.vim
?
推荐答案
按照 :help new-filetype-scripts
,
在用户运行时目录(~/.vim/
在类似Unix的系统上),并在其中编写以下脚本.
Following the instructions listed in :help new-filetype-scripts
,
create the scripts.vim
file in the user runtime directory (~/.vim/
on Unix-like systems), and write the following script in it.
if did_filetype()
finish
endif
if getline(1) =~# '^#!.*/bin/env\s\+node\>'
setfiletype javascript
endif
这篇关于如何使Vim从shebang行检测文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文