tags:

views:

510

answers:

4

In VIM in command line mode a "%" denotes the current file, "cword" denotes the current word under the cursor. I want to create a shortcut where I need the current line number. What is the symbol which denotes this?

+7  A: 

. (dot) stands for the current line.

To clarify: This is meant for stuff like :1,.s/foo/bar/g which will transform every foo to bar from the beginning of the file up to the current line.

I don't know know of a way to get the current line number expanded for a shell command, which is what you are trying to do by doing :!echo .

You can find out about the expansions that are done (like % and # for example) in :he cmdline-special.

WMR
This does not work. When I give a command:!echo .The output is just a "." instead of the line number expected.
akshat
No, this does not work, see my clarification. Maybe if you ask another question where you explain your planned shortcut in detail we can help you with another way to achieve what you intending.
WMR
thanks WMR. looking back at my question I realize that I did not correctly explain my requirement.PS: I had looked at cmdline-special but did not find this. I was hoping there was something not mentioned.
akshat
+1  A: 

Commands in vim works on the current line so:

:s/foo/bar/g

will transform every foo in bar on the line you are currently on.

Oli
I think the 'g' will cause it to substitute globally throughout the entire file.
Vulcan Eager
No, in this case the 'g' will cause the regex to be applied globally to the current line.
Tomalak
To do it globally, you need to put :%s/foo/bar/g OR :1,$s/foo/bar/g
Vijay Dev
+1  A: 

To return the line number of current line at bottom of screen, use:

:.=
Tomalak
+1  A: 

If you want to pass the current line number to a shell command, you could do

:exe "!echo " . line(".")
Brian Carper
Hi,That is an awesome answer. exactly what I was looking for.
akshat