简体   繁体   English

在vimrc中切换匹配

[英]Toggling a match in vimrc

I have the following lines in my vimrc file: 我的vimrc文件中包含以下几行:

hi ExtraWhitespace cterm=NONE ctermbg=green ctermfg=green guibg=green guifg=green
match ExtraWhitespace /\s\+$\|\t/

These lines will highlight all lines with no characters other than spaces as well as any tab. 这些行将突出显示所有行,除了空格和任何选项卡外,没有空格。 I would like to add a function that will toggle highlighting the whitespace. 我想添加一个将突出显示空白的功能。

map <F8> :call ToggleWhitespaceMatching()<cr>

I have tried to write my own, but have not been able to get it working. 我曾尝试编写自己的书,但未能使其正常运行。 Could someone please suggest a function to accomplish this. 有人可以建议一个功能来完成此操作。 Also, i would like the matching to be on, by default. 此外,我希望默认情况下启用匹配。

Similar idea to kev's but toggles the hilighting instead of the match 与kev相似的想法,但切换了提示而不是比赛

let s:hilightws = 1

hi ExtraWhitespace cterm=NONE ctermbg=green ctermfg=green guibg=green guifg=green
hi link MaybeExtraWhitespace ExtraWhitespace
match MaybeExtraWhitespace /\s\+$/    

fun ToggleWhitespaceMatching()
  if s:hilightws
    hi link MaybeExtraWhitespace NONE
    let s:hilightws = 0
  else
    hi link MaybeExtraWhitespace ExtraWhitespace
    let s:hilightws = 1
  endif
endfun

map <F8> :call ToggleWhitespaceMatching()<CR>

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

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