Getting the current row number?

1. Use :set ruler. (Works only in vim) Reference

It shows the current line and column of the line being edited (line where the cursor lies), at the bottom right corner of the widow.

1,1 <position>

  1. If first line is edited, position is Top.
  2. If last line is edited, position is Bot.
  3. If no scroll is available (both start and end lines are visible), position is All
  4. If no first and last lines are visible, position is the percentage of the document visible.

To make it permanent, add set ruler in ~/.vimrc file (if file is not there, create one).

2. Use :set number. (Works in both vi and vim) Reference

Displays the line number before every line.


Ctrl+G will tell you the line number and even the column the cursor is in. If you mean output it as text to your document, then not that I know of.


What do you mean by "output"? You can do:

:echo line(".") + 1

To display the current line number plus 1. You can bind a keystroke with map, eg:

:noremap <F1> :echo line(".") + 1<cr>

To actually insert the data into the buffer:

:noremap <F1> :execute "normal! i" . ( line(".") + 1 )<cr>

Tags:

Vi

Vim