Live data from Hacker News

Numbers.vim - better line numbers for vim

myusuf3.github.com

1–10 of 47 posts

Re: Numbers.vim - better line numbers for vim

#2
Do you really need a plugin for this?

If you want relative numbers to appear when in normal mode, and absolute line numbers to appear otherwise (e.g., when the window has lost focus), just throw this in your .vimrc:

    set rnu
    au InsertEnter * :set nu
    au InsertLeave * :set rnu
    au FocusLost * :set nu
    au FocusGained * :set rnu
Here's a gist for posterity. Feel free to fork it, leave comments on what should be changed, etc. The above has worked for me on Mac OS X for years, but there's a chance I didn't set it up the "right way". Leave comments on this gist and I'll update as necessary:

https://gist.github.com/3012145

Re: Numbers.vim - better line numbers for vim

#4

Do you really need a plugin for this? If you want relative numbers to appear when in normal mode, and absolute line numbers to appear otherwise (e.g., when the window has lost focus), just throw this in your .vimrc: set rnu au InsertEnter * :set nu au InsertLeave * :set rnu au FocusLost * :set nu au FocusGained * :set rnu Here's a gist for posterity. Feel free to fork it, leave comments on what should be changed, etc…

yeah, one because you forgot to surround it with an auto group. Plus its lines you don't have to write yourself.

Re: Numbers.vim - better line numbers for vim

#8

I'm still pondering the "how is this useful?" part... why are absolute numbers useful for you in insert mode?

My exact thought. I absolutely love 'relative line numbering' as it lets me use different VIM commands without having to do math. And as I can go to any line number by typing ':' [generally reported by debugger or other means], I don't really care about actual line numbers anymore.

Re: Numbers.vim - better line numbers for vim

#9

Do you really need a plugin for this? If you want relative numbers to appear when in normal mode, and absolute line numbers to appear otherwise (e.g., when the window has lost focus), just throw this in your .vimrc: set rnu au InsertEnter * :set nu au InsertLeave * :set rnu au FocusLost * :set nu au FocusGained * :set rnu Here's a gist for posterity. Feel free to fork it, leave comments on what should be changed, etc…

Also useful to hook BufLeave/BufEnter and WinLeave/WinEnter imo.

Re: Numbers.vim - better line numbers for vim

#10

I'm still pondering the "how is this useful?" part... why are absolute numbers useful for you in insert mode?

well when you moving around code you want to be in normal mode. so lets say you cursor is at the top of the function which would be 0 (with relative numbering) you could simply look down and see how many lines you need to delete. so for example lets say 5, then you could simply do 5dd or 5yy, without having to count all to see how many lines which can get annoying.

while in insert mode you would simply want to see what line you are one and for collaboration with others. In cases where you might want jump to a line like :15.

There is also a NumberToggle function if you ever need to switch on the go.

Post reply on HN