默认启用 Vim 语法高亮 [英] Enable Vim Syntax Highlighting By Default
问题描述
我知道如何通过在编辑器中运行来在 vim 中打开和关闭语法高亮:
I know how to turn syntax highlighting on and off in vim by running this in the editor:
:syntax on/off
但我希望默认启用语法高亮,所以我不必每次运行 vim 时都打开它.
But I want syntax highlighting to be enabled by default, so I don't have to turn it on every time I run vim.
我该怎么做?
推荐答案
编辑您的 $HOME/.vimrc
(Unix/Linux/OSX) 或 $HOME/_vimrc
(Windows) 包括以下行:
Edit your $HOME/.vimrc
(Unix/Linux/OSX) or $HOME/_vimrc
(Windows) to include the following line:
syntax on
编辑
如果您在启动 Vim 时语法高亮不起作用,您可能没有$HOME/.vimrc
或 $HOME/_vimrc
(从现在起统称为 vimrc
).在这种情况下,您有两个选择:
If your syntax highlighting doesn't work when you start Vim, you probably don't have a
$HOME/.vimrc
or $HOME/_vimrc
(known collectively as vimrc
from now on). In that case, you have two options:
- 创建一个空的
vimrc
. - 将
vimrc_example.vim
复制为您的vimrc
(推荐,感谢 @oyenamit).您可以在运行时目录中找到vimrc_example.vim
.
- Create an empty
vimrc
. - Copy
vimrc_example.vim
as yourvimrc
(recommended, thanks @oyenamit). You can findvimrc_example.vim
in the runtime directory.
运行时目录的位置因操作系统而异:
The location of the runtime directory varies between operating systems:
- 在我的系统(Arch Linux 和 Mac,感谢 @totophe)上,它位于
/usr/share/vim/vim73
. - 在 Windows 上,它位于
\Program Files\Vim\vim73
.
这篇关于默认启用 Vim 语法高亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!