Ask YC: Is vim worth learning and why?
Being a computer nerd, I am constantly being bombarded by fellow hackers singing the praises of vi/vim. I tried it out a few times, mostly from having to edit my nethackrc file on alt.org, but it doesn't feel very good. I feel trapped, like I can't see all my code at once, and I can't easily search around or explore. I can only edit and type at about 1/20th as fast as I can decide what I want to do. I can deal with hjkl being remapped on dvorak, but it's yet another annoyance.
I know that if I chose to learn all the nuances of vim, this would get better, but is it really worth learning? My editor of choice right now is gedit, and it's not meeting my needs, especially as my code files get larger than 4000 lines. I would be willing to spend some time being frustrated and annoyed learning a new editor if it was worth it in the long run.
Any suggestions? Should I hang in there until I learn all the nuances of vim?
The learning curve of vim is indeed steep, but it's been incredibly well worth it for me. The key thing to remember about vim is that it's very much oriented towards editing text, not so much creating it. (In general, writing lots of text is easy and there are few differences from editor to editor.)
But fast editing using only the keyboard is where vim really shines. In my experience, the biggest wins are the uniform command structures and the huge number of movement options. Since most commands in vim take the form of <number-of-repititions><command><movement area>, you need master only the various movement types to effectively start using a large number of commands. Movement areas (called "motions") can be word-by-word, long jumps within a sentence, going between paragraphs, matching code structures (braces/parenthesis/functions/etc.), etc. Learning these motions lets you quickly jump to exactly where you need to, resulting in super-fast editing.
Of course, there are all the usual search-and-replace type of commands, multiple buffers/screens/tabs, very easy macro recording and playback, and plugins for project management, source control, etc., but none of these particularly distinguish vim from other good editors.
The one 'weakness' of vim is that it's much less of an "OS" than editors like emacs. Instead, it has a few well-chosen external commands that are built-in (grep, make, etc.), and otherwise lets you run shell commands directly (piping input into the current file, if wanted) for everything else. This, IMO, is more in keeping with the unix mentality of piping together lots of small programs that each do one thing well. So for example, you can sort and keep only unique lines in a text file by simply selecting them and running the standard 'sort' and 'uniq' commands (exactly as you would do on the command line). Your personal preference is what decides whether this is a weakness (as emacs users would probably feel) or a strength (as I and many other vim users feel).
Finally, I would recommend learning vim as you would learn a new language: use it all the time and slowly pick up new features (not all at once) until you become proficient. I use it not only as my editor for all text and programming on my machine, but also for editing text boxes in firefox and editing emails in thunderbird. See http://news.ycombinator.com/item?id=152170 for more information.
I don't know if anyone goes back to old threads, but I just saw an article about using the vi command mode: http://news.ycombinator.com/item?id=217787
I'd forgotten to mention this as another important place to help learn vi. Command line sessions are almost all heavily editing-based, and vim really shines here (which, in addition to using zsh, gives you unbeatable command-line-fu).
As a passionate vim user: Yes! yes! yes!
Vim can do so many things, got so many features, you will easily forget about them the minute you've finished reading about them.
In my experience, the best way to learn your way around vim is this: If you have to do something, say, indent a dozen lines, instead of doing what I did for a long time–'I-tab-esc-j-I-tab-esc-j' etc etc–which obviously should be easier to do, google for a solution or look it up in the help file, and you will learn new tricks such as: (indent this and next four lines) 'V4j>'. Voila!
Else you can be stuck navigating with hjkl for years, and then it's not much fun.
y'see, this is the problem with vi users ;)
how on earth does 'V4j>' feel better than selecting the lines you want to indent, then pressing tab?
This is also where macro recorders work a treat; something like
<start macro> space * 4 home down <end macro> <run macro> * 3
Because I don't have to remove my hands from the keyboard to fool around with the mouse, and it's extremely powerful and you make clean cuts (eh??).
I'm almost never touching the mouse. I do a lot of stuff in the terminal, or using QuickSilver or memorizing all the ridiculous shortcuts different apps have. That way I can work at an incredible pace, and let the mouse sit in the corner.
You're responding to a vim/emacs comparison so I'll be the first to say you dont need to use the mouse in emacs just as you don't need it in vim. Hit ctrl-space to start a select. Move the cursor until your text is highlighted (you can skip to line if you know the number, also easy in emacs with setnu+), and then hit tab.
I didn't realize. I'm sure I saw a 'select with the mouse' somewhere in there. I didn't.
You can select with a mouse too. In my opinion, if you're using Emacs OR Vim you've already won. Apples and oranges, sure, but still fruit where notepad is kinda like a big mac.
I'm almost never touching the mouse.
Isn't this true for absolutely every programmer's text editor? Be it vi, emacs, visual studio, eclipse, whatever -- find an editor which can't do everything via the keyboard, and you've probably not got a real programmer's text editor.
What's particularly special about vi?
And, I think what's important is, that 'V4j>' seems a lot more difficult than selecting the lines and pressing tab. But when it becomes habit, you just do it, without putting further thought into it.
.. in the beginning it's horrible, though.
The beauty of vim is that the general paradigm is that you apply an action over a structured motion. For example, 'dib' will delete (d) the current inner block (ib), and put it into the paste buffer -- wonderful for pulling a block out into a method. Reformatting a paragraph works similarly -- gqap (gq = reflow, ap = a paragraph).
Vim's commands give you a language where you can refer directly to structured entities in your code, rather than being forced to speak in terms of numbers of lines, or cursor positions.
Now, that sounds pretty nice. This must need language-specific definitions -- a block in python is delimited differently than C, say.
What different things can you refer to? I know you can refer to words, lines, characters, buffers, and now blocks. Any other types?
actually it would be done with '5>>', which is a lot faster, or a command such as '>iB' (indent right inner block)
i've written many times why Vim is uber, but the short of it is that Vim is a high level editor
Why not learn Emacs instead? Emacs is incredibly extensible, and has a big community writing things for it to make code management really easy (which seems like a concern for you). Vi/Vim has lots of this too, I'm sure, but for me it's a no brainer to use Emacs. Oh, and if you're curious about Vi, there's viper-mode for Emacs that acts like Vi (http://www.emacswiki.org/cgi-bin/wiki/ViperMode).
Edit: viper-mode acts like vi, not vim
Invest in Mavis Beacon Teaches Typing instead! ;) Seriously, watch any screencast of a coder, and you'll see the thing that probably slows them down most is simple mistyping. The benefits of typing "<esc>:%s/replace/me/g" vs "<ctrl+h>replace<tab>me<enter>" are pretty minimal, I think. Anything that has a decent macro recorder and regex search-and-replace should be adequate.
The big win with vi seems to be that every shitty server in the world has a copy, even if you telneted in to some remote box in uzbekistan and the admin on the box feels that text editors are an unnecessary luxury. Still, other things seem more worth investing time in. I'm using Sublime Text (pretty, windows, python scriptable) as my main text editor. It's just nice to use something pretty. I think if you spend half your conscious life staring at it, make sure it's worth looking at. ;)
A screencast is not representative of actual coding. They already know what they're typing, and a few typos seems to dramatically slow them down. But, in real programming, you spend 80-90% of your time looking up library functions, flipping through your own code, reading comments, A/B testing various algorithm ideas, fixing the rendering in IE (actually this is probably 90% of your time...the other 10% is divided amongst all of the other activities), etc.
If you're spending more than 10% of your development time typing, you're probably coding things in the most naive way, and producing a lot more code than you should be. But even so, in six months, you'll probably be spending 90% of your time reading your code, because it's so verbose.
* But, in real programming, you spend 80-90% of your time [...]*
Well, yeah. But the question was about text editors -- how do you optimise that 10% of your time when you're actually cutting code? My point was, ultra-terse command syntax like vi's don't amount to much if what you're really typing is;
to get the string
into your source code. Also, typing matters more in dynamic languages or uncompiled source like html, where spelling mistakes can go undetected more easily.
The real benefits, as you note, are in things like automatic intellisense-style function- and class-lookups, easy integration with source control and documentation and refactoring/lint tools, and ease of navigating the call graph.
The big win, obviously, is live IE and firefox previewing ;) http://www.sublimetextwiki.com/cgi-bin/moin.cgi/BrowsersPlug...
some people like it, some people don't. if you don't like it, don't use it as your primary editor. it has its perks and it has its shortcomings.
however, whether its your main editor or not, learn the basics of vi so you don't flop around like a fish out of water when you need to use it, and you will need to use it sometime if you use *nix to some degree.
Speaking as a passionate vim user, If you're on dvorak, the advantages of vim are reduced quite a bit. The normal navigation keys are poorly placed, and the most commonly used keys are in hard-to-reach places.
However, at the same time, the statement "I feel trapped, like I can't see all my code at once, and I can't easily search around or explore." screams to me that you haven't even looked at the vim navigation.
I suggest you stick with learning vim, but look up cheat sheets and search for effective ways of navigating your code. Hint: ctags and ctrl+] is amazing for jumping around -- a tag stack is more or less essential IMO. the '*' (search forward for word under cursor) is also very useful.
My editor of choice right now is gedit, and it's not meeting my needs
Well, there's your answer.
I'm an emacs user so I recommend emacs. I know of many smart vi users so I recommend vi. I'm a Mac user so I recommend Textmate, but only if you really prefer it over emacs or vi (which are open source and ubiquitous -- you'll probably never need to learn another text editor ever again).
Learn one of those. Whichever one you like best. O'Reilly's Learning GNU Emacs was a very good book for me when I was a beginner; there's probably a similar book for vi.
I'd recommend learning your way around both vim and emacs. I'm primarily an emacs user myself, but vim comes in very handy once in a while.
You can edit code in an extremely productive manner in either editor, but you will be able to (pretty much literally) bend emacs to your will (allowing you to edit more or less however you want to) within a month or so of using it.
I have not used vim very much. I have a friend who does and it is his editor of choice. I personally use (and prefer) Notepad++. Its got a decent stable of shortcuts, loads up quickly, and works reasonably well with many languages.
Vim is massively useful for one simple reason: remote editing. I use BBEdit and Emacs for local files, but when I need to SSH into a remote server, there's nothing quite as fast and easy as firing up Vim to edit a config file.
Vim is worth learning for the profound enlightenment experience you will have when you finally switch to Emacs.