0

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.

2
  • 3
    Best way to find help on a Vim topic is CTRL-D. For example type :h \=<C-D> to see all the help tags that contain \=. In this case :s\= is the right one and you can find lots more information there. Commented Jan 9, 2014 at 21:18
  • @glts: +1 THANK YOU! This is an invaluable piece of advice. I was just thinking that the entire time I was grappling with the problem of finding out information about the \= expression, it was present within the application's help file, but I did not know how to access it. Thanks so much. Commented Jan 9, 2014 at 21:48

1 Answer 1

1

Some explanation:

  1. . expression will concatenate two strings. See :h expr-.
  2. | will separate to ex-commands. See :h :bar
  3. A replacement starting with \= in :s command means the rest of the replacement is to be treated as an vim expression. See :h :s\=
  4. Concatenate a string with a space after the Inc() function call. :let i = 1 | %s/^/\='LINE_' . Inc() . ' '/g
Sign up to request clarification or add additional context in comments.

2 Comments

I think I was the one who pushed you over 10K! Congratulations.
Glad I was able to help you. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.