Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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?

like image 403
akshat Avatar asked Nov 05 '08 19:11

akshat


People also ask

What is Vim command line mode?

vim has two "modes": COMMAND mode and INSERT mode. In COMMAND mode, you execute commands (like undo, redo, find and replace, quit, etc.). In INSERT mode, you type text. There is a third mode, VISUAL mode, that is used to highlight and edit text in bulk.

How do I insert a character in Vim?

Once in insert mode, typing inserts characters just like a regular text editor. You can enter it by using an insert command from normal mode. Insert commands include: i for 'insert', this immediately switches vim to insert mode.


2 Answers

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

like image 61
WMR Avatar answered Nov 16 '22 01:11

WMR


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

:exe "!echo " . line(".")
like image 26
Brian Carper Avatar answered Nov 16 '22 01:11

Brian Carper