我一直在处理很多没有扩展名的 C++ 文件,:set ft=cpp
每次打开它们时都必须输入太烦人了,所以我主要是在没有语法突出显示的情况下工作。有没有办法在命令行中告诉 vim 文件类型?就像是:
$ vim --ft=cpp file_name
Run Code Online (Sandbox Code Playgroud)
您可以-c
在启动 vim 时使用该选项在读取第一个文件后执行命令。
对于您的情况,您可以简单地使用标准set filetype
命令 -
vim -c 'set filetype=javascript'
Run Code Online (Sandbox Code Playgroud)
您还可以使用在加载第一个文件后--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.
Run Code Online (Sandbox Code Playgroud)