News for hackers. Stuff that matters.
Re:Numbers.vim - better line numbers for vim by theli0nheart on Thursday June 28, 2012 @11:34AM (#4172157)
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 by masukomi on Thursday June 28, 2012 @12:15PM (#4172386)
I just have this in my .vimrc which lets you toggle it whatever way you want in edit mode and it stays however you leave it when you toggle modes

    " use Ctrl+L to toggle the line number counting method
    function! g:ToggleNuMode()
    	    if(&rnu == 1)
        		set nu
	    else
		    set rnu
	    endif
    endfunc
    nnoremap <C-L> :call g:ToggleNuMode()<cr>
Re:Numbers.vim - better line numbers for vim by RegEx on Thursday June 28, 2012 @12:59PM (#4172618)
Quick note: This requires vim 7.3
Re:Numbers.vim - better line numbers for vim by fsaintjacques on Thursday June 28, 2012 @01:16PM (#4172710)
Thank you for sharing!
Re:Numbers.vim - better line numbers for vim by SkyMarshal on Thursday June 28, 2012 @03:27PM (#4173445)
One benefit of the plugin approach is that it will get forked and improved and other cool and useful things added to it. It's a central repository for all of that goodness, and keeping it up to date just requires pulling the repo (assuming you're using Pathogen or Vundle), instead of remembering to dig through vim.org/scripts periodically.

TLDR - the plugin approach gains the benefits of software evolution.

Re:Numbers.vim - better line numbers for vim by jamesrcole on Thursday June 28, 2012 @12:48PM (#4172556)
You don't need one. It's a cost/benefit thing - is it worth having one? Do you really need to use Vim or Emacs or Eclipse, etc? You don't need to.

I can imagine some reasons why it might be useful to have it as a plugin. Making a plugin means giving it a name and a URL (and if it's on vim.org, a place in a well-known directory), and that makes discovery and communication of its existence easier. The fact that it's useful to have a gist for it bears this out, I think. I can't think of why it's that bad a thing to have a plugin for it.

Re:Numbers.vim - better line numbers for vim by joshcorbin on Thursday June 28, 2012 @11:46AM (#4172227)
Also useful to hook BufLeave/BufEnter and WinLeave/WinEnter imo.
Re:Numbers.vim - better line numbers for vim by googletron on Thursday June 28, 2012 @11:36AM (#4172172)
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 by blackRust on Thursday June 28, 2012 @12:57PM (#4172613)
As someone with a low-bandwidth connection and that I often work in cafés I hate it when the only description available is through video when there could easily have been text and screenshots.
Re:Numbers.vim - better line numbers for vim by SkyMarshal on Thursday June 28, 2012 @03:22PM (#4173420)
Even on high bandwidth connections it's annoying. My read speed is much higher bandwidth than videos for things that can be explained in a paragraph or three.

Videos should probably be used when:

1. Your audience is non-technical.

2. A (moving) picture is worth a thousand words (eg, words can't do it justice, but a quick video can).

3. You're not bandwidth constrained (or firewalled).

4. You're not just video'ing text entry, or if you must, you ensure the user can zoom in or enlarge the video to see it (the embedded video can't be enlarged, I had to open it in Youtube to actually see it).

Re:Numbers.vim - better line numbers for vim by antidoh on Thursday June 28, 2012 @02:51PM (#4173272)
Or when you're behind a corporate firewall that prohibits youtube.
Re:Numbers.vim - better line numbers for vim by scott_w on Thursday June 28, 2012 @12:08PM (#4172356)
I know some people like line numbers, but personally, I just look at the status bar at the bottom of the buffer.

I find line numbers on the side clutter up my view too much. I always use 80 character terminal widths, to make it easier to stick to my PEP8 validation script we run.

Re:Numbers.vim - better line numbers for vim by dionidium on Thursday June 28, 2012 @12:30PM (#4172450)
That's fine for determining what line you're on, but visible line numbers make it much easier to jump to a particular line. I've only recently set number in my .vimrc and wish I'd have done it sooner.
Re:Numbers.vim - better line numbers for vim by ralph on Thursday June 28, 2012 @07:57PM (#4174562)
Do you use (){}[] and others to move about? I rarely need to know the line number to move to on the screen.
Re:Numbers.vim - better line numbers for vim by scott_w on Friday June 29, 2012 @04:43AM (#4175806)
That only really works well if the line you want is visible.

I've found searching to be much quicker, since I know class/method/variable names more than I know line numbers - we follow reasonably standard names for things in the projects we work on.

Re:Numbers.vim - better line numbers for vim by ori_b on Thursday June 28, 2012 @12:40PM (#4172510)
I do that by jumping to the particular line. :<linenum> or <linenum>G does that.
Re:Numbers.vim - better line numbers for vim by hesitz on Thursday June 28, 2012 @01:09PM (#4172671)
I think the point is that it's harder to see what line number you want to jump to if you don't have line numbering on. . . .
Re:Numbers.vim - better line numbers for vim by Scriptor on Thursday June 28, 2012 @01:16PM (#4172707)
Right, the alternative is to just sort of guess how much you need to ctrl-u/d or j and k to get to a specific line. Also, I guess it depends on screen size. I usually have plenty so the line numbers' usefulness outweighs the extra space required, at least for me.
Re:Numbers.vim - better line numbers for vim by dionidium on Thursday June 28, 2012 @01:35PM (#4172815)
Yes, that's exactly my point
Re:Numbers.vim - better line numbers for vim by dionidium on Thursday June 28, 2012 @01:37PM (#4172826)
Yes, that's how we all jump to a particular line :) It's just easier to target a specific line when numbering is turned on, as hesitz said.
Re:Numbers.vim - better line numbers for vim by nathan_long on Thursday June 28, 2012 @02:09PM (#4173005)
They also make it much easier to find the line number named in an exception backtrace. :)
Re:Numbers.vim - better line numbers for vim by guns on Thursday June 28, 2012 @12:59PM (#4172617)
I just tried turning off line numbers, and you're right, it's great. They really don't provide enough value to justify taking 4 columns on every vertical split.

I use a pretty large font size for my terminal, and the extra 8 columns finally allows for two 80 column vertical splits on my laptop. Thanks for the suggestion!

Re:Numbers.vim - better line numbers for vim by ilja on Thursday June 28, 2012 @01:39PM (#4172834)
There's also https://github.com/jeffkreeftmeijer/vim-numbertoggle which seems to do the same thing. I've been using that for a few months but i'm still not sure it's actually an improvement. It gets in the way almost as much as being actually useful.
Re:Numbers.vim - better line numbers for vim by foobarboomoo on Thursday June 28, 2012 @11:58AM (#4172294)
FWIW, the example you give would be more easily handled with the built in "dap" (delete a paragraph)
Re:Numbers.vim - better line numbers for vim by DougBTX on Thursday June 28, 2012 @06:50PM (#4174358)
Yea, that's what I had in mind while watching the video too. I remember that example as delete around paragraph, to match delete inside paragraph (dip), which differ in how they handle whitespace at the end of the paragraph. Delete inside quotes, di', and delete around quotes, da', work in the same way too.
Re:Numbers.vim - better line numbers for vim by joshcorbin on Thursday June 28, 2012 @11:38AM (#4172184)
I'm still pondering the "how is this useful?" part... why are absolute numbers useful for you in insert mode?
Re:Numbers.vim - better line numbers for vim by solutionyogi on Thursday June 28, 2012 @11:44AM (#4172219)
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 ':<line number>' [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 by brown9-2 on Thursday June 28, 2012 @12:16PM (#4172390)
In addition, if you have 'set ruler' set, the absolute line number of the current line is displayed at the bottom of the screen when in insert mode.
Re:Numbers.vim - better line numbers for vim by pwf on Thursday June 28, 2012 @01:37PM (#4172829)
I still feel like I have to do math (albeit simple math) with relative line numbering. If I want to yank a block of code that's X lines long, I have to look at line X, and add one to the number next to it. E.g., when I want to grab 8 lines, the last line I want to grab has a 7 next to it.

I guess I think it'd be more helpful if the numbers were inclusive, and 1-indexed. I'm not sure how to configure that though.

Re:Numbers.vim - better line numbers for vim by solutionyogi on Thursday June 28, 2012 @04:02PM (#4173617)
Yes, I wish the numbering was 1-indexed. But by now, I have trained my brain to automatically add one. I would definitely prefer a fix where I don't have to do +1.
Re:Numbers.vim - better line numbers for vim by alinajaf on Thursday June 28, 2012 @12:28PM (#4172446)
I've found it occasionally useful when pairing, i.e. "no no, I mean the call on line 23, not 28".
Re:Numbers.vim - better line numbers for vim by googletron on Thursday June 28, 2012 @11:53AM (#4172268)
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.

Re:Numbers.vim - better line numbers for vim by dionidium on Thursday June 28, 2012 @01:40PM (#4172839)
If you're operating on more than just a couple lines, then it's probably a bad sign to be doing math. It's usually better to navigate to the end of the selection and set a mark or select the text in visual mode.
Re:Numbers.vim - better line numbers for vim by ary on Thursday June 28, 2012 @12:46PM (#4172546)
Actually I'm more interested in seeing this guy's tmux config file.
Re:Numbers.vim - better line numbers for vim by hoov on Thursday June 28, 2012 @12:53PM (#4172586)
Re:Numbers.vim - better line numbers for vim by lloeki on Thursday June 28, 2012 @12:53PM (#4172587)
Re:Numbers.vim - better line numbers for vim by kamaal on Thursday June 28, 2012 @12:30PM (#4172457)
Its these kind of things that I wish to see vanilla vim shipped with, without bothering the user much.

Yes you can toss some commands and code snippets at me and ask me to use them to get these features. But not having to type commands/snippets and have all goodies out of the box is what modern text editors like sublime text are all about.

Re:Numbers.vim - better line numbers for vim by rhizome on Thursday June 28, 2012 @01:13PM (#4172693)
If you don't like typing, vim is not the right editor for you!
Re:Numbers.vim - better line numbers for vim by __float on Thursday June 28, 2012 @03:00PM (#4173330)
There's a difference in productive typing and typing to set up your editor. I would compare this to the popularity in Ubuntu vs Arch, too.
Re:Numbers.vim - better line numbers for vim by rhizome on Thursday June 28, 2012 @03:27PM (#4173447)
Well, it's not like it's Eclipse. I've been carrying my .vimrc and other dotfiles around from machine to machine for a decade. Occasionally I make changes, but for the most part there's not a lot of setup with vim for me.
Re:Numbers.vim - better line numbers for vim by gaving on Thursday June 28, 2012 @01:50PM (#4172899)
Anyone else just use visual mode for that kinna stuff?
Re:Numbers.vim - better line numbers for vim by outworlder on Thursday June 28, 2012 @11:36AM (#4172168)
What's with the funky status bar?
Re:Numbers.vim - better line numbers for vim by mgrouchy on Thursday June 28, 2012 @11:37AM (#4172176)
Thats his tmux Theme(outer) inner is powerline for Vim(https://github.com/Lokaltog/vim-powerline/), with a patched font.
Re:Numbers.vim - better line numbers for vim by fsniper on Thursday June 28, 2012 @02:12PM (#4173029)
That's what I was looking for. I love HN comments
Re:Numbers.vim - better line numbers for vim by lucisferre on Thursday June 28, 2012 @11:38AM (#4172182)
Was wondering that too one for tmux and a matching one for Vim. The author has his dotfiles up on Github so I'm planning on checking those out today.