Reputation: 36882
I'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
Upvotes: 7
Views: 3231
Reputation: 48006
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.
Upvotes: 14