Vim: toggle highlighting of long lines

北慕城南 提交于 2019-12-01 16:40:03

问题


In my .vimrc, I have:

:au BufWinEnter * let w:m1=matchadd('Search', '\%>80v.\+', -1)

to highlight lines that stray over the 80 character limit. How can I set it so that this is toggled on/off by pressing a function key?


回答1:


Use mappings.

To activate highlight:

:nnoremap <leader>1 :match Search '\%>80v.\+'<CR>

To deactivate it:

:nnoremap <leader>2 :match none<CR>

UPDATE to use same key/key combination to toggle highlight:

let s:activatedh = 0 
function! ToggleH()
    if s:activatedh == 0
        let s:activatedh = 1 
        match Search '\%>80v.\+'
    else
        let s:activatedh = 0 
        match none
    endif
endfunction

nnoremap <leader>1 :call ToggleH()<CR>


来源:https://stackoverflow.com/questions/19594119/vim-toggle-highlighting-of-long-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!