2

I'm running the command

:.,.5s/^/!&

to block comment a section of code, however, after running the command the editor highlights the first character in every line of the file. I guess this doesn't surprise me since those characters match the regex, but I thought this would be suppressed if I add a range.

3

Standing on the shoulders of giants

I would highly recommend commenting plugin like commentary (which I use), Nerd Commenter, EnhCommentify, tComment, ..., etc. There is no shame in using a plugin.

  • so far commentary is very useful, thanks for the suggestion. – toweleeele Jul 30 '15 at 19:45
3

:.,.5norm I! is an alternative that doesn't use substitution.

By the way, you can shorten your original command like this:

:,.5s/^/!

,or like that:

:,+5s/^/!

Also, I don't know if you are aware of that but you can prepend your ex command with a count to automatically insert the right range:

6:s/^/!

gives:

:.,.+5s/^/!

And this is yet another way:

:s/^/!/6

But yeah, use commentary.

0

After performing a search, you can hide the highlights by running

:noh

which is short for :nohlsearch. After your next search, the highlights will re-appear.

I actually have this mapped to Ctrl-L so it's even easier to perform.

nmap <silent> <C-L> <C-L>:nohlsearch<CR>:match<CR>:diffupdate<CR>

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.