Reputation: 5264
I am using the following Vim command line that inserts line numbers to the beginning of lines:
:let i = 1 | %s/^/\='LINE_' . Inc()/g
Inc()
is a function that increments the i
variable.
This is all working fine. My questions:
1) What does the dot do in the replacement part?:
:let i = 1 | %s/^/\='LINE_' . Inc()/g
^
2) What does the pipe character do? Is there actual piping going on, or is it just syntax?
3) What does the \=
do? I think it is used to call the function, but Vim help only shows information for \=
as being a quantifier in regex.
4) I have not been able to insert a space after the line number and the first character of the actual line. How can I do this? Anything I place after Inc()
in the replacement part is either being ignored or causing an E15 invalid expression error.
I am using Vim 7.3 on Windows 7.
Upvotes: 0
Views: 133
Reputation: 45117
Some explanation:
.
expression will concatenate two strings. See :h expr-.
|
will separate to ex-commands. See :h :bar
\=
in :s
command means the rest of the replacement is to be treated as an vim expression. See :h :s\=
Inc()
function call. :let i = 1 | %s/^/\='LINE_' . Inc() . ' '/g
Upvotes: 1