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:
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>
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.
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.
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.
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).
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.
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.
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.
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.
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!
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.
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.
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.
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.
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.
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.
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.
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.
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.
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:
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