with

setl nu!

I can toggle number (on/off), similar with relativenumber

setl rnu!

how I can toggle {off,number,relativenumber} ?

link|improve this question

63% accept rate
2  
aw. why on earth was this question migrated to SU? It is a programming question related to a prorgramming tool. It doesn't get more SO than that. The programmers that focus on SO (like me) would now not be able to find this answer because 5 people don't know what vim is. Go figure. META: meta.stackoverflow.com/questions/25925/vim-questions-so-or-su – sehe Sep 25 '11 at 12:01
@sehe, I agree , this is a question for stackoverflow – juanpablo Sep 25 '11 at 15:52
feedback

migrated from stackoverflow.com Sep 25 '11 at 9:54

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 5 down vote accepted
if &nu == 1
   set rnu
elseif &rnu == 1
   set nornu
else
   set nu
endif
link|improve this answer
thanks Benoit, I added your solution as a gist – juanpablo Sep 24 '11 at 20:17
1  
@JuanPablo: mmm. I like my version better :) – sehe Sep 24 '11 at 20:19
@sehe: I'd say the same about my version. :-) – ib. Sep 25 '11 at 3:51
feedback

Because I love a logic puzzle, and really love it when a vim command fits on a single line for succinct repeats (@: is a personal favourite):

:exec &nu==&rnu? "se nu!" : "se rnu!"

This will maintain the same cycle. I think it is mainly because let &nu=1 will implicitly set norelativenumber - for reasons probably found in the documentation :)

link|improve this answer
2  
+1 as I can place it in my .vimrc file as one line of nmap <F3> :exec &nu==&rnu? "se nu!" : "se rnu!"<CR> to toggle through three options using F3. – nye17 Sep 24 '11 at 23:38
2  
you could make that nnoremap <silent> <F3>... to reduce visual distraction and interfering with other mappings. – sehe Sep 24 '11 at 23:56
I came up with almost the same (but shorter :-) line when read the question: exe'se'&nu+&rnu?'rnu!':'nu'. – ib. Sep 25 '11 at 2:51
By the way, to assure yourself of the connection between number and relativenumber options, see :helpg When setting this option. – ib. Sep 25 '11 at 2:54
@ib: thanks for sharing. I really love your vim code golfs - there are gems in there that really speed up my everyday work; In this case, however, I have specificly selected my version (a net 3 characters longer - besides whtiespace cramp) because it is legible. In my view, there isn't any gain from condensing it further: it does get harder to type and a lot harder to remember even if you ever had to type it from memory. This is going to be in a mapping. So Benoit's version is fine, except for it not fitting nicely on a single line – sehe Sep 25 '11 at 12:08
show 8 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.