Wikia

Vim Tips Wiki

Changes: Sample switch between number/nonumber

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 15: Line 15:
 
function! NumberNo()
 
function! NumberNo()
 
set nonumber
 
set nonumber
map <F12> :call NumberYes()<CR>
+
map <F12> :call NumberYes()<CR>
 
endfunction
 
endfunction
   
 
function! NumberYes()
 
function! NumberYes()
 
set number
 
set number
map &lt;F12&gt; :call NumberNo()&lt;CR&gt;
+
map <F12> :call NumberNo()<CR>
 
endfunction
 
endfunction
map &lt;F12&gt; :call NumberNo()&lt;CR&gt;
+
map <F12> :call NumberNo()<CR>
 
</pre>
 
</pre>
   
Line 29: Line 29:
   
 
<pre>
 
<pre>
:map &lt;F12&gt; :set number!&lt;CR&gt;
+
:map <F12> :set number!<CR>
 
"" for insert mode
 
"" for insert mode
:imap &lt;F12&gt; &lt;c-o&gt;:set number!&lt;CR&gt;
+
:imap <F12> <c-o>:set number!<CR>
 
</pre>
 
</pre>
   
Line 38: Line 38:
   
 
<pre>
 
<pre>
:map &lt;F12&gt; :let &amp;number=1-&amp;number&lt;CR&gt;
+
:map <F12> :let &number=1-&number<CR>
 
</pre>
 
</pre>
   
Line 50: Line 50:
 
exec s:current_winnr."winc w"
 
exec s:current_winnr."winc w"
 
endfunc
 
endfunc
map &lt;F12&gt; :call &lt;SID&gt;NumToggle()&lt;CR&gt;
+
map <F12> :call <SID>NumToggle()<CR>
 
</pre>
 
</pre>
   
Line 57: Line 57:
   
 
<pre>
 
<pre>
noremap &lt;silent&gt; &lt;F12&gt; :if &amp;number \| set nonumber \| else \| set number \| endif&lt;cr&gt;
+
noremap <silent> <F12> :if &number \| set nonumber \| else \| set number \| endif<CR>
 
</pre>
 
</pre>
   
Line 64: Line 64:
   
 
<pre>
 
<pre>
noremap &lt;silent&gt; &lt;F12&gt; :set number!&lt;cr&gt;
+
noremap <silent> <F12> :set number!<CR>
 
</pre>
 
</pre>
   

Latest revision as of 09:21, September 29, 2008

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