Is there a pattern like ^ in vim?
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?
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.
To match the first non-whitespace character, you'd just use \S
like you normally do.
If you use ^
in a regex in vim, it will match the actual start of the line, even if it contains whitespace.
For instance, this line starts with a space:
<- there's a space there you can't see :)
This vim command will remove the leading space:
:%s/^ //
resulting in the following:
<- there's a space there you can't see :)
So, the regex will behave as you expect, even if the command doesn't.