Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command for toggling line numbers in vi

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.

like image 318
Mohammed H Avatar asked Feb 20 '13 08:02

Mohammed H


People also ask

How do I jump a line number in vi?

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.

How do I show line numbers in less command?

You can easily display line numbers using less command. All you have to do is pass either -N or --LINE-NUMBERS option to the less command. This option forces less to show a line number at the beginning of each line in the screen.

How do I show line numbers in terminal?

To turn on relative line numbers: Press Esc to enter command mode. Press colon (:). Type set relativenumber (or set rnu), then press Enter.


2 Answers

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

like image 196
MechanTOurS Avatar answered Sep 30 '22 14:09

MechanTOurS


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.

like image 21
Kent Avatar answered Sep 30 '22 15:09

Kent