在命令行上指定vim filetype(Specify vim filetype on command line)

编程入门 行业动态 更新时间:2024-10-25 17:17:43
命令行上指定vim filetype(Specify vim filetype on command line)

我一直在处理很多没有扩展的C ++文件,每次打开它时都要输入:set ft=cpp太烦人了,所以我大多只是在没有语法高亮的情况下工作。 有没有办法告诉vim命令行中的文件类型? 就像是:

$ vim --ft=cpp file_name

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

最满意答案

在读取第一个文件后启动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.

更多推荐

本文发布于:2023-07-22 19:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222737.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   vim   filetype   command   line

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!