Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle absolute and relative numbering in VIM by insert/normal mode

Tags:

vim

I use the relative line number setting in vim. I would like vim to automatically switch to absolute line numbers when I am in insert mode and back to relative in normal mode. Currently I have tried this code in my vimrc

  autocmd InsertEnter * :set number                                                                                                                                                                                                      
  autocmd InsertLeave * :set relativenumber 

Unfortunately this only gets me part of the way there. This toggles on relative numbers the first time I leave insert mode, but will no longer go back to absolute numbers upon entering insert mode again.

like image 422
Riley Hughes Avatar asked Apr 24 '17 04:04

Riley Hughes


People also ask

How do I hide numbers in Vim?

Make the vi/vim text editor show or hide line numbers Press ESC key. At the : prompt type the following command to run on line numbers: set number. To turn off line numbering, type the following command at the : prompt set nonumber.


1 Answers

First, do a

set number

Then

autocmd InsertEnter * :set norelativenumber
autocmd InsertLeave * :set relativenumber 
like image 100
thiagowfx Avatar answered Oct 07 '22 01:10

thiagowfx