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.
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.
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
In vim, many options support this set
pattern, (for example, foo
):
"enable the option
set foo
"disable it
set nofoo
"toggle the option
set foo!
"get option's current value
set foo?
for number
, map a key to :set nu!
would be ok.
You can toggle any (boolean) option using the !
suffix, i.e. :set number!
would toggle displaying line numbers.
The on-board help for this command is a bit hidden; while one would think :help toggle
would get you there, it doesn't quite. Using :help set-!
is the magic word.
I use relative line numbers, for all lines above and below the current line, together with absolute line numbering for the current line. But this is only working since Vim 7.4.
This is sometimes named “Hybrid” line numbering (e.g. in the article https://jeffkreeftmeijer.com/vim-number/)
To toggle from "no numbers at all" to "hybrid" you can use the following config:
set number relativenumber " Turn line numbering on at startup
" Toggle line numbers from none at all
" to relative numbering with current line number
noremap <F3> :set invnumber invrelativenumber<CR>