Wikia

Vim Tips Wiki

Sample switch between number/nonumber

Talk0
1,613pages on
this wiki
Revision as of 09:21, September 29, 2008 by JohnBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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>
endfunction

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

CommentsEdit

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"
endfunc
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>

Around Wikia's network

Random Wiki