我一直在处理很多没有扩展的C ++文件,每次打开它时都要输入:set ft=cpp太烦人了,所以我大多只是在没有语法高亮的情况下工作。 有没有办法告诉vim命令行中的文件类型? 就像是:
$ vim --ft=cpp file_nameI've been working with a lot of C++ files that have no extensions and it's too annoying to have to type :set ft=cpp every time I open them, so I'm mostly just working without syntax highlighting. Is there a way to tell vim the file type in the command line? Something like:
$ vim --ft=cpp file_name最满意答案
在读取第一个文件后启动vim以执行命令时,可以使用-c选项。
根据您的情况,您只需使用标准set filetype命令 -
vim -c 'set filetype=javascript'您还可以在加载第一个文件后使用--cmd执行命令。
从vim手册页中解脱出来:
-c {command} {command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} contains spaces it must be enclosed in double quotes (this depends on the shell that is used). Example: Vim "+set si" main.c Note: You can use up to 10 "+" or "-c" commands. --cmd {command} Like using "-c", but the command is executed just before processing any vimrc file. You can use up to 10 of these commands, independently from "-c" commands.You can use the -c option when launching vim to execute commands after the first file has been read.
For your situation, you can simply use the standard set filetype command -
vim -c 'set filetype=javascript'You could also use --cmd to execute the command after the first file is loaded.
Lifted from the vim man pages:
-c {command} {command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} contains spaces it must be enclosed in double quotes (this depends on the shell that is used). Example: Vim "+set si" main.c Note: You can use up to 10 "+" or "-c" commands. --cmd {command} Like using "-c", but the command is executed just before processing any vimrc file. You can use up to 10 of these commands, independently from "-c" commands.更多推荐
发布评论