0

When review code, it would be convenient if we can highlight multiple lines at the same time, instead of only current cursor line is highlighted.

:set cursorline only highlight current line.
:nnoremap <silent> <Leader>l ml:execute 'match Search /\%'.line('.').'l/'<CR> can only highlight one extra line.

Want to keep all marked lines highlighted.

  • You question is a bit too broad so far: are you talking about cursorline or some syntax highlighting? And on which criterion would you like to highlight your lines? – statox Jun 21 '18 at 8:35
  • Requirement is simple: move cursor to line a, highlight current line; move cursor to another line b, highlight it, ..., keep all marked lines highlighted. It doesn't need syntax highlighting. cursorline can only highlight current line. – Fisher Jun 21 '18 at 8:46
  • 1
    I don't think it is possible to keep some lines highlighted while doing something else than visual selection. One possible solution would be to add these two lines to your .vimrc: syntax region CoreReview start=/"CR/ end=/"RC/ and highlight 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. – statox Jun 21 '18 at 11:17
2

As you mention in your question, the :match command only allows a single match to be set up. For multiple matches, you can use the matchadd() function. You can adapt your existing mapping to use this like so:

:nnoremap <silent> <Leader>l :call matchadd('Search', '\%'.line('.').'l')<CR>

For your expressed purpose of reviewing code, this should be sufficient. However, if you are adding/removing lines above the lines you have marked, this might not work as you desire: the marks will not move with the lines. There are ways around this, but all will result in much more complicated code.

0

Thanks for below answer, find a way to highlight multiple lines. https://superuser.com/a/697070/366981

Install plugin:multiselect-2.2.zip.
Ctrl and left click to select and highlight any line.
Ctrl and left click again to remove highlight.
<leader>mscto clear all selection.

enter image description here

Another method: Highlight multiple words enter image description here

-1

You press capital V and j or k to select other lines.

  • 1
    This only select continuous lines? – Fisher Jun 21 '18 at 16:22
  • I can see why you'd think the OP wants what you think. But you're wrong. You should remove your answer from here. – klaus Jun 22 '18 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.