By pressing Ctrl-N twice in normal mode, Vim toggles between showing and hiding line numbers.

By pressing Ctrl-N twice in normal mode, Vim toggles between showing and hiding line numbers.

+

==Enabling Line Numbers on Startup==

+

+

To enable line numbers on startup, simply add the following to your [[.vimrc]]

+

+

<code>set number</code>

+

+

or:

+

+

<code>set nu</code>

+

+

==Adding Line Numbers Only to Certain Files==

+

+

You may only want to have line numbers on certain files (like code files) and not have them enabled on other buffers (like your [[NERD Tree Plugin|NERD Tree]] window). If so, you can add the following code to line 5 of your ''ftplugin.vim'' file ('''NOTE:''' On *nix systems, it is located at '''/usr/share/vim/vim73/ftplugin.vim'''):

+

+

<code>set number</code>

+

+

or:

+

+

<code>set nu</code>

+

+

==Changing Gutter Column Width==

If you have Vim version 7 or greater, you can change the width of the "gutter" column used for numbering:

If you have Vim version 7 or greater, you can change the width of the "gutter" column used for numbering:

−

:set numberwidth=3

+

<code>:set numberwidth=3</code>

You can use the number column for the text of wrapped lines:

You can use the number column for the text of wrapped lines:

−

:set cpoptions+=n

+

<code>:set cpoptions+=n</code>

Finally, you can change the color used for the line numbers. For example:

Finally, you can change the color used for the line numbers. For example:

Creating a Mapping to Toggle Line Numbers

By pressing Ctrl-N twice in normal mode, Vim toggles between showing and hiding line numbers.

Enabling Line Numbers on Startup

To enable line numbers on startup, simply add the following to your .vimrc

set number

or:

set nu

Adding Line Numbers Only to Certain Files

You may only want to have line numbers on certain files (like code files) and not have them enabled on other buffers (like your NERD Tree window). If so, you can add the following code to line 5 of your ftplugin.vim file (NOTE: On *nix systems, it is located at /usr/share/vim/vim73/ftplugin.vim):

set number

or:

set nu

Changing Gutter Column Width

If you have Vim version 7 or greater, you can change the width of the "gutter" column used for numbering:

:set numberwidth=3

You can use the number column for the text of wrapped lines:

:set cpoptions+=n

Finally, you can change the color used for the line numbers. For example: