简体   繁体   English

在标签页中打开文件时采购vimrc?

[英]sourcing vimrc when opening a file in tab page?

I have a the following in my vimrc to highlight any lines that go past 80 columns: 我的vimrc中有以下内容以突出显示超过80列的所有行:

highlight ColorColumn ctermfg=red ctermbg=bg
call matchadd('ColorColumn', '\%81v.\+', 100)

It works great in most cases. 它在大多数情况下都很好用。 However, I've noticed that if i open a file in a new tab, it doesn't work at all. 但是,我注意到如果我在新标签中打开文件,它根本不起作用。 I'm able to fix this by :source $MYVIMRC . 我能够解决这个问题:source $MYVIMRC But the issue is, when I source my vimrc I lose my indentLines plugin. 但问题是,当我找到我的vimrc时,我丢失了我的indentLines插件。 I've done a little testing, and I have found that the indentLines goes away anytime the vimrc is sourced in an open instance of vim. 我做了一些测试,我发现只要vimrc来自vim的开放实例,indentLines就会消失。 Still, I am unable to determine why the 2 lines shown above are not being called when I open a file in a new tab. 但是,当我在新选项卡中打开文件时,我无法确定为什么没有调用上面显示的2行。 Any ideas? 有任何想法吗?

my vimrc 我的vimrc

The matchadd() only affects the current window. matchadd()仅影响当前窗口。 In order to have it on all windows you can add the following to your .vimrc: 要在所有窗口中使用它,您可以将以下内容添加到.vimrc:

if exists("*matchadd")
   augroup colorColumn
      au!
      au BufEnter * call matchadd('ColorColumn', '\%81v.\+', 100)
   augroup END
endif

Edit: As pointed by Ingo on the comments, the BufEnter will trigger many times when it is not necessary. 编辑:正如Ingo在评论中指出的那样, BufEnter会在没有必要时多次触发。 The lines below correct this issue: 以下几行纠正了这个问题:

if exists("*matchadd")
   augroup colorColumn
      au!
      au VimEnter,WinEnter * call matchadd('ColorColumn', '\%81v.\+', 100)
   augroup END
endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM