Vim Tips Wiki

Sample switch between number/nonumber

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 757 Printable Monobook Previous Next

created July 2, 2004 · complexity basic · author panshdw · version 6.0

function! NumberNo()
  set nonumber
  map <F12> :call NumberYes()<CR>

function! NumberYes()
  set number
  map <F12> :call NumberNo()<CR>
map <F12> :call NumberNo()<CR>


This also works:

:map <F12> :set number!<CR>
"" for insert mode
:imap <F12> <c-o>:set number!<CR>

Another alternative is:

:map <F12> :let &number=1-&number<CR>

I do this -- which inverts the 'number' option for every window:

func! s:NumToggle()
  let s:current_winnr = winnr()
  windo set invnumber
  exec s:current_winnr."winc w"
map <F12> :call <SID>NumToggle()<CR>

You can also do this:

noremap <silent> <F12> :if &number \| set nonumber \| else \| set number \| endif<CR>

Yes, but it's faster to just do:

noremap <silent> <F12> :set number!<CR>

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki