Skip to content

Instantly share code, notes, and snippets.

@dlo
Created June 28, 2012 15:53
Show Gist options
  • Save dlo/3012145 to your computer and use it in GitHub Desktop.
Save dlo/3012145 to your computer and use it in GitHub Desktop.
Relative Line Numbers in Vim
set rnu
au BufEnter * :set rnu
au BufLeave * :set nu
au WinEnter * :set rnu
au WinLeave * :set nu
au InsertEnter * :set nu
au InsertLeave * :set rnu
au FocusLost * :set nu
au FocusGained * :set rnu
@isuldor
Copy link

isuldor commented Feb 6, 2014

Vim 7.4 introduced a hybrid mode that shows both relative number and the line number you're currently on. Now that either mode is non-exclusive I think you'll need to disable the current mode to toggle.

@jviotti
Copy link

jviotti commented Mar 30, 2015

@brianbaligad is right. My current setup is:

set number
set relativenumber

augroup linenumbers
  autocmd!
  autocmd BufEnter *    :set relativenumber
  autocmd BufLeave *    :set number norelativenumber
  autocmd WinEnter *    :set relativenumber
  autocmd WinLeave *    :set number norelativenumber
  autocmd InsertEnter * :set number norelativenumber
  autocmd InsertLeave * :set relativenumber
  autocmd FocusLost *   :set number norelativenumber
  autocmd FocusGained * :set relativenumber
augroup END

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment