Vim 特定文件中的 80 个字符行

Vim 80 character line in specific files

我最近开始使用 Vim。我在 .vimrc 中设置了 80 个字符的行,使用以下命令:

set colorcolumn=80

但并非所有文件中都显示此行。请看下面的屏幕截图:

我的 .vimrc 是 here。有谁知道,问题是什么?

您的 vimrc 中分散了以下行:

" higlight column right after max textwidth
set colorcolumn=+1

" Disable vertical line at max string length in NERDTree
autocmd FileType * setlocal colorcolumn=+1
autocmd FileType nerdtree setlocal colorcolumn=""

set colorcolumn=80

同样重要的是,您显然没有将 'textwidth' 设置为任何值,因此它应该是默认值零,并且来自 vim 'colorcolumn' 上的帮助:

When 'textwidth' is zero then the items with '-' and '+' are not used.

所以,我怀疑正在发生的事情是 * 作为通配符的自动命令是 运行 并设置 colorcolumn=+1,这基本上是禁用它,因为 'textwidth' 为零。

因此,您可以通过确保设置 'textwidth' 或删除自动命令来解决问题。而且,更一般地说,您应该清理 vimrc 中 'colorcolumn' 的各种设置,以免相互抵消/干扰。