Using Vis Structural Regexes
The vis editor is a great drop-in vim replacement that supports a feature known as structural regexes. The idea of strucutral regexes is best illustrated by example:
one something
two something
unrelated
three something
another
four something
In the above snippet, to obtain the selection of lines only containg the word "something", you could use the x command as :x/.*something.*/
on the list, to obtain the selection:
one something
two something
three something
four something
Now further, say you only want to match only the remaining lines for three something
.. You have two options. Either use x command again to re-select (:x/.*three.*/
). Or the more interesting alternative is to use the g command (:g/three/
) to conditionally filter selections matching the regex. Both results will give you:
three something
The g command can be thought of as an if-regex-filter-loop and x as reselect-regex-loop. Also at your disposal are the v and y commands which are the inverse of g and x.
- For more comprehensive documentation check out the vis man page and also Rob Pike's original paper on structural regexes.