|
|
| (4 intermediate revisions by 4 users not shown) |
| Line 11: |
Line 11: |
| |
|category2= |
|
|category2= |
| |
}} |
|
}} |
| |
+ |
== Enabling/Disabling Line Numbers in Vim == |
| |
+ |
|
| |
+ |
===Enabling=== |
| |
This will display line numbers along the left side of a window: |
|
This will display line numbers along the left side of a window: |
| |
|
|
|
| − |
:set number |
+ |
<code>:set number</code> |
| |
|
|
|
| |
+ |
or: |
| |
+ |
|
| |
+ |
<code>:set nu</code> |
| |
+ |
|
| |
+ |
===Disabling=== |
| |
+ |
This will turn off the line number display: |
| |
+ |
|
| |
+ |
<code>:set nonumber</code> |
| |
+ |
|
| |
+ |
or: |
| |
+ |
|
| |
+ |
<code>:set nonu</code> |
| |
+ |
|
| |
+ |
or: |
| |
+ |
<code>:set nu!</code> |
| |
+ |
|
| |
+ |
===Creating a Mapping to Toggle Line Numbers=== |
| |
You can also define a mapping to toggle the option, for example: |
|
You can also define a mapping to toggle the option, for example: |
| |
|
|
|
| − |
:nmap <C-N><C-N> :set invnumber<CR> |
+ |
<code>:nmap <C-N><C-N> :set invnumber<CR></code> |
| |
|
|
|
| |
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== |
| |
+ |
|
| |
+ |
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: |
| |
+ |
|
| |
+ |
<code>setl number</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: |
| |
|
|
|
| − |
:highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE |
+ |
<code>:highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE</code> |
| |
|
|
|
| |
==References== |
|
==References== |
Enabling/Disabling Line Numbers in Vim
Edit
This will display line numbers along the left side of a window:
:set number
or:
:set nu
Disabling
Edit
This will turn off the line number display:
:set nonumber
or:
:set nonu
or:
:set nu!
Creating a Mapping to Toggle Line Numbers
Edit
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
Edit
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
Edit
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
Edit
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
Edit