This answer may be a couple years late but since I just had the same question, and none of these answers were even close to being helpful I though I'd share my solution.
I was wanting to improve my mapping that is similar to OP's that highlights a single line :
nnoremap <leader>l :call matchadd('LineHighlight', '\%'.line('.').'l')<cr>
to be able to visually select multiple lines and highlight all of them.
After being unsuccessful trying to simply modify the mapping to a vnnoremap
that takes a range I wrote a function that will run a loop for each line in the selection.
highlight LineHighlight ctermbg=100 guibg=#374090
vnoremap <leader>l :<c-u>call HiglightVisualLines()
nnoremap <leader>c :call clearmatches()
" HiglightVisualLines()
" loop throough visually selected lines and give them highlighting
function! HiglightVisualLines()
for i in range(line('v'),line("'>"))
call matchadd('LineHighlight', '\%'.i.'l')
endfor
endfunction
As Rich mentioned with his comment, the highlighting is based on line number, not the content of the line, so adding lines above the highlighting will 'break' it.
cursorline
or some syntax highlighting? And on which criterion would you like to highlight your lines?cursorline
can only highlight current line..vimrc
:syntax region CoreReview start=/"CR/ end=/"RC/
andhighlight CoreReview ctermbg=LightGreen
. You can then put"CR
at the beginning of the code you are reviewing and"RC
at the end to highlight the background. It is even possible to create a mapping which will add the markers for you when you are in visual selection and remove them when you don't need them anymore.