Created
June 28, 2012 15:53
-
-
Save dlo/3012145 to your computer and use it in GitHub Desktop.
Relative Line Numbers in Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Updated!
after applying this, you can't just set 'nonumber' in vim anymore (i.e to copy text into another application). you'll have to do the following:
set nu
set nonumber
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.
@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
I found that this wasn't setting relative numbers when I would load a file, so I added a couple of events based on another commenter's post: