Sunday, January 26, 2014

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: GPGTools - http://gpgtools.org

iQIcBAEBAgAGBQJS5MEoAAoJEHWv8EScabi8k7UP/iVQ+RoOXIDFpotp2WtMzg/i
f+HGaxhXlfzKz2AHrf/w0X0F0USOi4wsHiTORs4Nfapr3i+BLO8Hbp51+OirsWyC
10OxX4zrAv9XnFU7GNW2WTrGmzDg5Ka2bPSpA6behKDGeZS0R9cbvglAeCArlhQE
XFnkaDfxwS+yZPhtO7ZDk+lCMlyVncK+9WBS6GuapLECt2oraCHUQIAfJs7McKJG
dgpzdlWZncUADxPei58GKPxNVzA1xKXs1E4eLWc5zV+m/S7VZXOXIKEJWVTqqvuO
yxhyCIfK8fZt+ElqcRyrNj3EGLfSQbDv1SnxA6d2yeO/nTH6JJx4JpS+ntjd8Z7Y
eQ89uUAaN2wfMsJLb3kHfl/P61W7VC9HEC0ml88pZesdl7mKtLWmKZGLJv8L7+DQ
U4jxLIyToHkJ38oQdTmjka8IN6x+ztvT7e8GNRWfjtZJDURzjJG4kggAKdR8jqWl
LyBrmK+xaXdQxBf/v8C7LGEUTRnvcb/Q2EqpnEhQyWsq2LthS1Jo/225Ov39WaZ9
TmxTPaRqZHgTca/7y75WvMQfgDL4tQngK4Y6RI3/8u0bLyU7obs3RNkISp7p0hH+
uxST6A2QWuZBBlru+rOruMZkMPxDCDopwxnr5q3LMCPBqSmuNEyQKaLQE+CXpfYP
6YZhMUbZ1FFzdPcMcR/L
=b/4X
-----END PGP SIGNATURE-----
On 26 Jan 2014, at 5:59, Marc Weber wrote:

> 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| (*)

Good to know, I have to save this somewhere. Thanks.

Niels

No comments:

Post a Comment