如何使Vim从家当线检测文件类型? [英] How to make Vim detect filetype from shebang line?
本文介绍了如何使Vim从家当线检测文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有时我写剧本没有任何文件扩展名。例如:
Sometimes I write scripts without any filename extension. For example:
#!/usr/bin/env node
console.log('hello world!');
我希望Vim可以检测来自shebang行的文件类型(如#!的/ usr / bin中/ env的节点
是的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
?
推荐答案
按照 :帮助新的文件类型的脚本
,
创建在用户运行时目录中的的scripts.vim
文件(〜/的.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从家当线检测文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文