Last active
June 28, 2017 21:51
-
-
Save tjdevries/e3c6c442b967332488fa32f9669dc1ae to your computer and use it in GitHub Desktop.
Highlight overlength
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let g:highlight_overlength = v:true | |
let g:highlight_overlength_length = 72 | |
let g:load_overlength = v:true | |
" Use :call ToggleOverlength() | |
" to toggle whether or not you show highlights | |
function! ToggleOverlength() abort | |
let g:highlight_overlength = !g:highlight_overlength | |
if g:highlight_overlength | |
call HighlighOverlength() | |
else | |
call ClearOverlength() | |
endif | |
endfunction | |
" Use :call ClearOverlength() | |
" to just clear the current highlights | |
" They will probably show up again when you enter the buffer again though. | |
function! ClearOverlength() abort | |
if exists('w:last_overlength') | |
" Just try and delete it | |
" Don't worry if it messes up | |
try | |
call matchdelete(w:last_overlength) | |
catch | |
endtry | |
unlet w:last_overlength | |
endif | |
endfunction | |
function! HighlighOverlength() abort | |
call ClearOverlength() | |
if g:highlight_overlength | |
if !exists('w:last_overlength') | |
let w:last_overlength = matchadd('OverLength', '\%' . g:highlight_overlength_length . 'v.*') | |
endif | |
endif | |
endfunction | |
if g:load_overlength | |
augroup vimrc_autocmds | |
au! | |
autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#8b0000 | |
autocmd BufEnter * call HighlighOverlength() | |
augroup END | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment