Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: toggle highlighting of long lines

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?

like image 220
AlexJ136 Avatar asked Oct 25 '13 15:10

AlexJ136


1 Answers

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>
like image 154
Birei Avatar answered Sep 22 '22 18:09

Birei