On 12/03/10 15:05, Jean Johner wrote:
Hello,
I would like to add a "c" (c character) at the beginning of a line (or
of a range) for any character already present at column 1. This means
that if "c" is the first character of the line, I want to get "cc". If
it is "a", I want to get "ca".
Using
:s/a*/c/
works because * can be zero so that *a can be an empty string.
Unfortunately, if "a" is the first character of the line, the command
results in c replacing a (not inserting before a).
Is there a way to solve this problem, for example by representing an
empty string in an absolute manner.
I tried /.*/ but it replaces the whole line.
I tried // but it represents the last search string.
Best regards.
Jean Johner
There are various ways to go about this. For instance the following:
:'<,'>s/^\ze\a/c/
which means
: start of ex-command
'<,'> this range is automagically inserted if you hit :
in Visual mode; it means "on all selected lines".
s s[ubstitute]
/ start of "replace what" regex
^ begin of line
\ze "replace what by" ends here, but continue matching
\a alphabetic character
/ start of "replace by what" string
c c
/ end of "replace by", there are no flags
see :help pattern-overview
To replace any character (not only alphabetic), but not empty lines,
replace \a by a dot.
Best regards,
Tony.
--
The human animal differs from the lesser primates in his passion for
lists of "Ten Best".
-- H. Allen Smith
--
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