1

假设我在 vim 中加载了一个 python 文件。快速检查:scriptnames显示我的~/.vim/ftplugin/python/python.vim文件按预期加载。此文件中的命令之一突出显示超过第 80 列的所有字符。现在假设我在另一个缓冲区中打开了一个 C++ 文件(因此运行~/.vim/ftplugin/cpp/cpp.vim)。尽管执行了新命令,但python.vim仍然适用其中的设置;因此字符在我的 C++ 文件的第 80 列之后突出显示。

反正有没有像这样使文件类型命令不累积?我filetype plugin indent on在我的.vimrc.

4

1 回答 1

3

The problem is that both 'colorcolumn' and :match (you didn't specify whether you use the new setting or the older highlight approach) are local to the window, but ftplugins should only set buffer-local settings.

Why are these settings window-local? That allows you to have the same buffer displayed in two windows, one with, and one without the highlighting.

What can you do to prevent this?

a) Don't set this in the ftplugin, and instead use mappings to toggle the colorcolumn on/off.

b) Put :setlocal nocolorcolumn into all ftplugin scripts (e.g. in ~/.vim/after/ftplugin/*.vim) for all filetypes that you're using. This will only work unless you switch between different filetypes in the same window.

c) The correct (but most complex) way to solve this is through a couple of :autocmds on BufWinEnter, BufWinLeave, and WinLeave events.

于 2012-12-21T03:05:31.733 回答