5 points · by AndyKelley · 18y ago · 24 comments
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?
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'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).
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.
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
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.
What different things can you refer to? I know you can refer to words, lines, characters, buffers, and now blocks. Any other types?
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.
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?
.. in the beginning it's horrible, though.
i've written many times why Vim is uber, but the short of it is that Vim is a high level editor
Edit: viper-mode acts like vi, not vim
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. ;)
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.
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;
arr(<back>[3<back>2];<back>
to get the string arr[2]
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...
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.
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.
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.
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.