Reputation: 11
I want to implement a function that cycles through setting the line numbers.
I'm having trouble evaluating the state of the number command. For instance I have tried:
function! CycleNumbers()
if exists(":number")
set nonumber
elseif exists(":nonumber")
set number
endif
endfunction
Is there a way to test for number being off? Something like number==off?
Thank you for your help
Upvotes: 0
Views: 47
Reputation: 40499
You can toggle an option with the exclamation mark (on the command line):
:set number!
See also :help set-!
If you insist on having a function, then you want something like
fu! CycleNumbers()
set number!
endfu
Edit
If you want to query the current value of the option, you use the &option
syntax:
if &number == 0
...
else
...
endif
Upvotes: 3
Reputation: 195059
why not check the option value? something like :
let &number = &number? 0: 1
or simply as you said in comment, set nu!
to get the information, if line number is shown, read &number
variable. if it's 1
the number is currently showing. 0
, not.
something like:
if &number
"showing
else
"not showing
endif
fill your logic codes there.
Upvotes: 4