VIM:match none命令在输入时不工作。vimrc
我的.vimrc中有以下内容VIM:match none命令在输入时不工作。vimrc,vim,vi,Vim,Vi,我的.vimrc中有以下内容 syn match ErrorLeadSpace /^ \+/ " highlight any leading spaces syn match ErrorTailSpace / \+$/ " highlight any trailing spaces syn match Error80 /\%>80v.\+/ " highlight anything past 80 in red au FileType
syn match ErrorLeadSpace /^ \+/ " highlight any leading spaces
syn match ErrorTailSpace / \+$/ " highlight any trailing spaces
syn match Error80 /\%>80v.\+/ " highlight anything past 80 in red
au FileType c match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
au FileType c highlight error ctermbg=red guibg=red ctermfg=blue guifg=blue
au FileType h match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
au FileType h highlight error ctermbg=red guibg=red ctermfg=blue guifg=blue
因此,vim会高亮显示前导/尾随空格,或者一行中超过80个字符的多余字符
但是,目前,我想禁用此“错误”突出显示。
目前,我通过在打开的文件中使用命令“match none”来实现这一点。然而,当我把这个命令放在.vimrc文件中时,它不起作用
如何在对.vimrc进行最小更改的情况下实现这一点?在
.vimrc
文件中,match none
命令不起作用,因为您将高亮显示规则放入了au
命令中(这是一个非常好的主意)。每次编辑新的C文件时,au
都会执行,而.vimrc中的match none
命令将毫无用处,因为它在加载时很久以前就已经来源了
你给出的代码中有几个问题;我在下面解释。但您可以这样做,例如:
highlight CError ctermbg=red guibg=red ctermfg=blue guifg=blue
function! DefineAugroup_For_C()
augroup MyCAugroup
au!
au FileType c match CError /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
augroup END
endf
" Enable the automatic highlight for future edited files, and also for the current one:
command! SetHighlightForC call DefineAugroup_For_C()|exe "set ft=".&ft
" Disable the automatic highlight for future edited files, and also for the current one:
command! UnsetHighlightForC augroup! MyCAugroup|match none
" Comment this line to unable the automatic highlight on load:
SetHighlightForC
然后,您可以按如下方式取消激活/激活高亮显示:
:UnsetHighlightForC
:SetHighlightForC
au FileType c,cpp,php match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
我认为您的代码中存在一些问题:
- 前三行不引用任何现有的突出显示(
、ErrorLeadSpace
和ErrorTailSpace
),因此除非您使用Error80
命令在另一个位置定义它们,否则它是无用的。(至少,这对你的问题没用)突出显示
- 另一个问题是,您不需要添加以下行:
因为C头文件没有au FileType h match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/ au FileType h highlight error ctermbg=red guibg=red ctermfg=blue guifg=blue
文件类型,而是h
文件类型以及源文件。默认情况下,C
文件类型不存在。要知道文件的文件类型,请执行以下操作:h
:set ft?
- 另一件事:如果要为多个文件类型添加相同的规则,可以只在一个命令中添加它们,方法是用逗号分隔文件类型,如下所示:
:UnsetHighlightForC :SetHighlightForC
au FileType c,cpp,php match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
- 在
.vimrc
文件中,match none
命令不起作用,因为您将突出显示规则放入了au
命令中(这是一个非常好的主意)。每次编辑新的C文件时,au
都会执行,而.vimrc中的match none
命令将毫无用处,因为它在加载时很久以前就已经来源了
你给出的代码中有几个问题;我在下面解释。但您可以这样做,例如:
highlight CError ctermbg=red guibg=red ctermfg=blue guifg=blue
function! DefineAugroup_For_C()
augroup MyCAugroup
au!
au FileType c match CError /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
augroup END
endf
" Enable the automatic highlight for future edited files, and also for the current one:
command! SetHighlightForC call DefineAugroup_For_C()|exe "set ft=".&ft
" Disable the automatic highlight for future edited files, and also for the current one:
command! UnsetHighlightForC augroup! MyCAugroup|match none
" Comment this line to unable the automatic highlight on load:
SetHighlightForC
然后,您可以按如下方式取消激活/激活高亮显示:
:UnsetHighlightForC
:SetHighlightForC
au FileType c,cpp,php match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
我认为您的代码中存在一些问题:
- 前三行不引用任何现有的突出显示(
、ErrorLeadSpace
和ErrorTailSpace
),因此除非您使用Error80
命令在另一个位置定义它们,否则它是无用的。(至少,这对你的问题没用)突出显示
- 另一个问题是,您不需要添加以下行:
因为C头文件没有au FileType h match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/ au FileType h highlight error ctermbg=red guibg=red ctermfg=blue guifg=blue
文件类型,而是h
文件类型以及源文件。默认情况下,C
文件类型不存在。要知道文件的文件类型,请执行以下操作:h
:set ft?
- 另一件事:如果要为多个文件类型添加相同的规则,可以只在一个命令中添加它们,方法是用逗号分隔文件类型,如下所示:
:UnsetHighlightForC :SetHighlightForC
au FileType c,cpp,php match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
- 在
.vimrc
文件中,match none
命令不起作用,因为您将突出显示规则放入了au
命令中(这是一个非常好的主意)。每次编辑新的C文件时,au
都会执行,而.vimrc中的match none
命令将毫无用处,因为它在加载时很久以前就已经来源了
你给出的代码中有几个问题;我在下面解释。但您可以这样做,例如:
highlight CError ctermbg=red guibg=red ctermfg=blue guifg=blue
function! DefineAugroup_For_C()
augroup MyCAugroup
au!
au FileType c match CError /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
augroup END
endf
" Enable the automatic highlight for future edited files, and also for the current one:
command! SetHighlightForC call DefineAugroup_For_C()|exe "set ft=".&ft
" Disable the automatic highlight for future edited files, and also for the current one:
command! UnsetHighlightForC augroup! MyCAugroup|match none
" Comment this line to unable the automatic highlight on load:
SetHighlightForC
然后,您可以按如下方式取消激活/激活高亮显示:
:UnsetHighlightForC
:SetHighlightForC
au FileType c,cpp,php match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
我认为您的代码中存在一些问题:
- 前三行不引用任何现有的突出显示(
、ErrorLeadSpace
和ErrorTailSpace
),因此除非您使用Error80
命令在另一个位置定义它们,否则它是无用的。(至少,这对你的问题没用)突出显示
- 另一个问题是,您不需要添加以下行:
因为C头文件没有au FileType h match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/ au FileType h highlight error ctermbg=red guibg=red ctermfg=blue guifg=blue
文件类型,而是h
文件类型以及源文件。默认情况下,C
文件类型不存在。要知道文件的文件类型,请执行以下操作:h
:set ft?
- 另一件事:如果要为多个文件类型添加相同的规则,可以只在一个命令中添加它们,方法是用逗号分隔文件类型,如下所示:
:UnsetHighlightForC :SetHighlightForC
au FileType c,cpp,php match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
- 在
.vimrc
文件中,match none
命令不起作用,因为您将突出显示规则放入了au
命令中(这是一个非常好的主意)。每次编辑新的C文件时,au
都会执行,而.vimrc中的match none
命令将毫无用处,因为它在加载时很久以前就已经来源了
你给出的代码中有几个问题;我在下面解释。但您可以这样做,例如:
highlight CError ctermbg=red guibg=red ctermfg=blue guifg=blue
function! DefineAugroup_For_C()
augroup MyCAugroup
au!
au FileType c match CError /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
augroup END
endf
" Enable the automatic highlight for future edited files, and also for the current one:
command! SetHighlightForC call DefineAugroup_For_C()|exe "set ft=".&ft
" Disable the automatic highlight for future edited files, and also for the current one:
command! UnsetHighlightForC augroup! MyCAugroup|match none
" Comment this line to unable the automatic highlight on load:
SetHighlightForC
然后,您可以按如下方式取消激活/激活高亮显示:
:UnsetHighlightForC
:SetHighlightForC
au FileType c,cpp,php match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/
我认为您的代码中存在一些问题:
- 前三行不引用任何现有的突出显示(
、ErrorLeadSpace
和ErrorTailSpace
),因此除非您使用Error80
命令在另一个位置定义它们,否则它是无用的。(至少,这对你的问题没用)突出显示
- 另一个问题是,您不需要添加以下行:
自au FileType h match error /\s\+$\|\%>80v.\+\|[ ][ ]\+\|\n\n\n\+\|,[^ ]\|^[ ]\+[^\*]\|(\s\+\|\s\+)/ au FileType h highlight error ctermbg=red guibg=red ctermfg=blue guifg=blue