vim set regextype perl

The problem

Vim is a great editor. I use it every day, and that includes weekends. I’ve run into an issue where to search with the regular expression (dest|path): I needed to escape the parentheses and the pipe. That gets tedious.

The solution

I found my solution at stackoverflow: http://stackoverflow.com/questions/5770058/vim-and-regular-expression-what-kind-of-regex-does-vim-use/26600989#26600989.

At the beginning of your search expression, use \v which then uses a “very magic” regex mode in which fewer escapes are needed.

/\v(dest|path):

Show all non-blank non-comment lines in file

If you want to see just the lines with content, such as in a config file, use this one-liner:

grep -viE '^\s*((#|;).*)?$' smb.conf

How it works

grep -v means invert the selection, i.e., everything that does not match this search.
-iE case Insensitive, and treat this as a regular Expression. Technically there are no letters being searched, so the i is irrelevant, but I always use it in my searches anyway.
^ start of line
\s* white space, any amount from zero onward. This is a greedy search, so it will match all the white space (spaces, tabs, etc.)
(#|;) either a pound or a semicolon, which usually denote comments in config files (in my case, smb.conf)
((#|;).*) the above sentence, followed by any character (the period), and any amount of those “any characters.”
((#|;).*)? the whole thing in parentheses shown here, optionally.
$ end of line
So any line that starts with any amount of white space, followed by (a comment symbol, followed by anything else) optionally, and the end of the line.
So show everything but the above sentence, and tada, just the important stuff.