在命令行上指定vim文件类型

时间:2016-07-18 15:29:36

标签: vim

我一直在处理很多没有扩展名的C ++文件,每次打开它时都要输入{​​{1}}太烦人了,所以我主要是只是没有语法高亮的工作。有没有办法告诉vim命令行中的文件类型?类似的东西:

:set ft=cpp

1 个答案:

答案 0 :(得分:3)

在启动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.