vim question

Smylers Smylers at
Thu Apr 3 09:45:22 BST 2008

Ovid writes:

> --- Adrian Lai <perl at> wrote:
> > Try v$ to select to the end of the line.
> > Then :s/\%V:/ /g to do the actual replace.
> Why didn't this just stop the conversation?

You _do_ know which mailing list this is?

> It works great.
> And thanks Adrian.  I've often wanted something like %V, but didn't
> know about it until now.

For what it's worth there's also \%# for the cursor position, so the
substitution can be done in a single command (no need to invoke visual
mode) with:

  :s/\v(%#.*)@<=:/ /g

To replace all occurrences after the cursor position you want to assert
that each one is preceded by the cursor position (then anything at all);
so that occurrences don't overlap you want a zero-width look-behind
assertion for this, which in Vim is \@<= after the token in question,


But all those backslashes are make it hard to read; it's simpler to put
a \v at the start of the pattern instead:


Irritatingly though both this and the visual mode solution that Adrian
mentioned move the cursor to the start of the line (first non-blank;
same as pressing ^).  Ctrl+O jumps back to where it was, but when the
substitution itself is sensitive to the cursor position it's suboptimial
for it to move.


More information about the mailing list