Saturday, January 25, 2014

Re: Replacing a string which is in a line and not in the beginning?

Excerpts from Niels Kobschaetzki's message of Sat Jan 25 11:37:24 +0100 2014:
> And I want to replace all occurrences of "- " when they are not at the
> beginning of the line. So the above mentioned file should look like:

There are always two ways to cope with this "if they are not". Fastest:

(This assumses " - " is still meant to be beginnig of the line, thus
even if there are leading spaces)
:%s/^(\s*)- /\1DONT_REPLACE_THIS/
:%s/- //
# substitute DONT_REPLACE_THIS back:
:%s/^(\s*)DONT_REPLACE_THIS/\1- /

second way is looking up all that "no match" magic in :h regexp
Eg: |/\@!| \@! \@! nothing, requires NO match |/zero-width| (*)

Marc Weber

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: