Saturday 6 January 2007 — This is nearly 18 years old. Be careful.
I find myself using vi (often vim actually) a lot these days, not for large chunks of code, but for small scripts and configuration files on a variety of Linux servers. You can get along in vi using just the hjkliESC keys, but sticking with those is really limiting. I’m getting to the point where I remember to use other commands, and so it’s time to read again about all the vi commands, and try to increase my repertoire. These two references look useful:
I can’t quite explain why vim feels like my editor of choice for these sorts of occasional edits on Linux: I guess because it’s ubiquitous and a little familiar.
Comments
Once you understand the sentence structure of Vim commands, it becomes a lot easier to figure out the right command for whatever text modifications you're trying to do.
My hot tip is to get familiar with the :ex commands. My favorite is the :global command (abbeviated to :g) which executes another command on every line that matches a regular expression. The command to execute defaults to 'print', so for example
:g/^ *def/
will print every function definition in a python file.
The command that global runs can also have a range modifier, so for example:
:g/^ *def/ -3,+3p
will print every function definition and the three lines before and after, while
:g/^# *TODO/ ?^class? p
will find every line with a TODO comment, then search backwards for the class definition and print that.
I also recommend upgrading to Vim 7 wherever possible, since it adds many useful new features.
http://tnerual.eriogerg.free.fr/vimqrc.pdf
Oh, and welcome to the dark side. :)
My calculation is somewhat simple: If it requires more keystrokes to control the editor than it takes to actually change the content, I'm probably using the wrong tool. The corollary: If using the tool require using more than one modifier key in a row (ctrl, alt) or backslashes, its probably the wrong tool for quick edits.
Yes, those who live-and-love E(macs) or V(i/im) are welcome to them, of course; I know they can edit circles around me. I just don't have the patience to memorize the "sentences" or idioms for E or V. Every year, I try, and every year, I laze on back to nano. One day, someone will discover that the presence of nano or pico is what's been holding back the conquering of Linux over Windows, it'll be dropped from distros, and I'll be in trouble...
http://here.the.ycros.be/article/the-omnipotent-vim
Auto-completion is something that I miss in vim but it doesn't exist for ruby (AFAIK) and using it in eclipse tends to slow me down or cause typos because the computer is slower than my typing or thinks I want something I don't, unless of course I'm working in an unfamiliar code-base, in which case it's pretty useful. There's a vi plugin for eclipse but last time I checked it wasn't free.
Couldn't agree more.
:q!
Add a comment: