Command for toggling line numbers in vi

Mohammed H picture Mohammed H · Feb 20, 2013 · Viewed 24.8k times · Source

I know

:set number

and

:set nonumber

I want to know whether there is any command in vi/vim

:set togglenumber

to display line number if the line numbers is not showing or hiding line numbers if line numbers is showing.

Answer

MechanTOurS picture MechanTOurS · Feb 20, 2013

You can use (on VIM at least):

:set invnumber

More Info:

:set number      Turn line numbers on
:set nonumber    Turn line numbers off
:set invnumber   Toggle line numbers
:set number!     Toggle line numbers
:set number&     Set option to default value
:set number?     Show value of option 

source: http://vim.wikia.com/wiki/Managing_set_options#Boolean_options