Pattern like ^ in vim

regexvim

In Vim normal mode, the 0 command takes you to the first column on the line and ^ takes you to the logical start of line (e.g. the first non-whitespace character). In the regex world, ^ matches the first character on the line, whitespace or not. Does Vim have a pattern that behaves like its '^' command–matching the logical beginning of a line?

Best Answer

There's no shortcut to match the first non-whitespace character on a line, you have to build the pattern yourself, like:

^\s*restofpattern

If you don't want to include the whitespace in your match, you have to use a zero-width assertion, like:

\(^\s*\)\@<=restofpattern

Not exactly pretty, but at least it gets the job done.

Related Question