No edit summary |
(→Adding Line Numbers Only to Certain Files: You shouldn't change any of the files distributed by Vim, they will be overwritten on upgrades. Use filetype plugins!) |
||
Line 53: | Line 53: | ||
==Adding Line Numbers Only to Certain Files== |
==Adding Line Numbers Only to Certain Files== |
||
+ | Create a filetype plugin for each filetype where you'd like to have numbering enabled (see {{help|ftplugin-overrule}}) and add the following line to it: |
||
− | 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> |
+ | <code>setl number</code> |
− | |||
− | or: |
||
− | |||
− | <code>set nu</code> |
||
==Changing Gutter Column Width== |
==Changing Gutter Column Width== |
Revision as of 09:09, 16 January 2013
created February 25, 2001 · complexity basic · author scrott · version 5.7
Enabling/Disabling Line Numbers in Vim
Enabling
This will display line numbers along the left side of a window:
:set number
or:
:set nu
Disabling
This will turn off the line number display:
:set nonumber
or:
:set nonu
or:
:set nu!
Creating a Mapping to Toggle Line Numbers
You can also define a mapping to toggle the option, for example:
:nmap <C-N><C-N> :set invnumber<CR>
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
Create a filetype plugin for each filetype where you'd like to have numbering enabled (see :help ftplugin-overrule) and add the following line to it:
setl number
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:
:highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
References
- :help 'number'
- :help 'numberwidth' (Vim 7 and greater only)
- :help :highlight