akshat
akshat

Reputation: 15922

In VIM command line mode what is the special character/symbol for current line?

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?

Upvotes: 13

Views: 4286

Answers (4)

Brian Carper
Brian Carper

Reputation: 72926

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

:exe "!echo " . line(".")

Upvotes: 11

WMR
WMR

Reputation: 12971

. (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.

Upvotes: 14

Tomalak
Tomalak

Reputation: 338228

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

:.=       

Upvotes: 2

Oli
Oli

Reputation: 15940

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.

Upvotes: 1

Related Questions