How to display the line number in Vim?

13

I'm using the Vim text editor GVIM on a Windows-based machine.

How can I show the line numbers? Provided that I'm not using it in the console?

Simplicity

Posted 2011-01-25T12:43:16.397

Reputation: 229

Not an answer to your question but might be helpful still. I use :set ruler which shows cursor position. – johnny – 2011-01-25T19:04:18.813

Answers

18

Run :set number to add a left margin with the line numbers. Use :help 'nu to see help on the topic, including changing the margin size.

For some permanence, place the command, without the leading colon, in ~/.vimrc on UNIX/Linux based systems or in %HOMEPATH%\_vimrc.

Arcege

Posted 2011-01-25T12:43:16.397

Reputation: 1 883

add 'and if you like your settings save them to .vimrc' – akira – 2011-01-25T13:39:30.623

@Arcege, @akira. I'm actually new to this. I ran :set number on VIM, and got a black blank screen with "1" written at the top left I think indicates the line number. How can I make this effect occur to GVIM? @akira, you mentioned saving to .vimrc. Will that do the job? If so, ho can I make this save? Thanks. – Simplicity – 2011-01-25T13:59:07.847

1Since you are on Windows, the file might be _vimrc (underscore instead of a '.'). It would reside in the user directory (not desktop): C:\Users\myusername\ or C:\Documents and Settings\myusername, check the the help (:help vimrc). Any of the statements that start with a colon (':') can be placed in that file (without the colon). The same settings and vimrc are used for gvim. – Arcege – 2011-01-25T14:45:34.763

@SWEngineer: open gvim and type ':set number' .. now you have the 1 in the top left corner as well :) check out what @Arcege said about the place of _vimrc and read ':help _vimrc' – akira – 2011-01-25T16:13:30.070

@Arcege. I found _vminfo at the location you suggested, and there was :set numer, but I couldn't see the line numbers. Why is that? Thanks. – Simplicity – 2011-01-25T19:48:21.450

@akira. I did what you mentioned and got what you said, but how can I make the line numbers appear in an already written file? Thanks. – Simplicity – 2011-01-25T19:49:23.760

@SWEngineer _vminfo is not a settings file. You want to create a _vimrc with set number inside it in the same folder as the _viminfo file. The _vimrc file is a 'personal settings' file and _viminfo is the 'local cache' (which could be deleted without affecting anything). – Arcege – 2011-01-26T01:45:49.910

3

:set number

will add the line numbers to the left hand side of the buffer.

You can put that setting, along with any others you enjoy inside your .vimrc file and they will automatically get loaded whenever you start an instance of VIM.

.gvimrc is generally reserved for specific settings you want loaded when you open gvim as opposed to terminal sessions of vim or vi. More often than not this file has graphical considerations that the X server can handle.

TCopple

Posted 2011-01-25T12:43:16.397

Reputation: 131

-1

:set nu 

should display the line numbers

:set nonu  or :set nu!

will make the line numbers vanish.

RoyOneMillion

Posted 2011-01-25T12:43:16.397

Reputation: 211