Sometimes I just want to see whether a regex is matching the right stuff. If I could cause Vim to visually select the matching text, it would be one way to do this. Is there a method for doing this?
Vim will use a colour for search matches if you have the
'hlsearch' option switched on:
You can then just search for your regular expression and see if it is highlighted:
Note that, if you also have
'incsearch' set, Vim will begin highlighting matches as soon as you start typing in your regular expression: with that option disabled the highlighting won't occur until you execute the search by pressing Enter.
Search highlighting group is used for highlighting. You can check how this group is configured with the command:
When you are done, you can remove the highlighting with the command:
Note the difference between this and
:set nohlsearch, which turns off search highlighting entirely: the
:nohlsearch command leaves the
hlsearch option on, and will only turn off highlighting until the next time you search.
:help 'hlsearch' for more details.
This can be achieved with
:h gn for details.