(Useful) Stupid Vim Tricks? 702
haroldag writes "I thoroughly enjoyed the recent post about Unix tricks, so I ask Slashdot vim users, what's out there? :Sex, :b#, marks, ctags. Any tricks worth sharing?"
Politics: A strife of interests masquerading as a contest of principles. The conduct of public affairs for private advantage. -- Ambrose Bierce
Re:Just using VIM (Score:5, Insightful)
If you are on a single box, that is fine. But when you have to admin about 500 servers, spread out across the country, and sometimes over a dial-up link, you often don't have a graphical environment available. Even on the local network, I often ssh from one box to the next, and forget to forward my X11 connections. Since vi is always available, that is what I use.
The other thing is that I appreciate having only minimal hand movement to get around a file and make changes. Much like people used to love the Word Star diamond, the same thing with vi's ctrl-f, ctrl-b, h, j, k, l, etc. And since I've been using it for about 20 years, these commands are second nature to me. Not to mention the search/replace supporting regular expressions (something a lot of gui word processors don't have).
Re:Just using VIM (Score:5, Insightful)
Try using most GUI editors on a remote server over ssh. Kate may be an exception with KDE's nice network abstraction I don't know (I use Gnome), but to be honest for me the main utility of vi is that I know it's going to be there in any Linux enviroment (and I suspect Unix in general).
Stack Overflow (Score:5, Insightful)
When did Slashdot become Stack Overflow?
Re:Stupid vi tricks? (Score:5, Insightful)
Ah, add "set compatible" to your .vimrc file and you have 99% vi behavior.
Why would you use plain vi, when vim is so much better?
Re:Just using VIM (Score:3, Insightful)
Yes, please tell me about your years spent on Ultrix, Altos and other boxes. You modern kidz and your GUI. The main reason why I use OSX is because I can ssh *and* run Microsoft office at the same time. If you don't understand syntax like
run *kermit
load * (Oh, the magical keys on the c64)
and having to spend time at bps rates lower than 9600 when performing tasks, you clearly don't appreciate the speed increases over the years the same as some of us. I remember going from 300->1200->2400bps. Now I spent my time tracking IEEE HSSG for 100Gb/s interfaces, because I will likely have a need to bundle them.
I get really sad when I see wasteful memory and cpu bloat. Perhaps these will become scarce resources again with the mobile trend, and people will do a better job watching their consumption. Oh well.
Re:Just using VIM (Score:5, Insightful)
I use Vim primarily because I can perform almost any task without moving my fingers from the standard typing position. I certainly feel much more efficient being able to (for example) use j/k/l/h for movement than moving my hand over to the arrow keys, or worst, to the mouse. That's one of many tasks which simply becomes natural over time (in fact, when I'm typing in a web form, I frequently find myself trying to use Vi shortcuts) and which really make things go more smoothly for me. Even when I'm on a full desktop, I prefer using Vim. I only wish the OS X port of gvim worked better.
The reason that I don't use EMACS is because of the finger gymnastics you have to perform for even the simplest of tasks. Of course, one could complain similarly about Vi--having to switch to command mode is something that gets just about every single newbie.
Re:Just using VIM (Score:5, Insightful)
Amen. Know vi, and know the bourne shell, and you're good on close to 100% of the unix machines you'll ever touch.
Some basic but useful commands (Score:2, Insightful)
Very basic commands, but the ones I use the most are:
o - Open a new line in insert mode
cw - Delete word and enter insert mode (change word)
dw - Delete word
d$/c$ - Delete/Change to end of line
dd - Delete Line and Yank
yy - Yank Line
p - Paste
These simple commands alone make Vi/Vim very fast for editing.
Re:Just using VIM (Score:4, Insightful)
I personally recommend trying to learn Vim alongside with another editor, or using a GUI frontend like GVim.
Replace Vim or GVim with any editor of your choice.
Re:Just using VIM (Score:2, Insightful)
This reminds me of the not-quite-a-joke: A programmer will spend 30 days writing a script that saves him 30 seconds ... every time he uses it. Using vim (or emacs, for those that insist ;) is the same way; you spend time up front to learn how it works only to save truly stupendous amounts of time later when the "obscure commands and meta-keystrokes" you now know saves you minutes to hours per file.
The keyboard is the same. (Score:3, Insightful)
The keyboard hasn't changed in the 100 years and that is the main bottleneck. Vi is the most efficient keyboard interface to a text file I know of.
Emacs is nicer to use at first and is just as efficient for very simple and very complex edits but it's poorer in the middle. The trade off (both ways) is what gives the nice "community spirit".
The editors you mention don't even have the concept of complex edits and frequently require you to drag you hands away from the home keys, not just to the further reaches of the keyboard (like emacs) but right off the keyboard. This is the sort of thing that can break your concentration (ie WTF has happened to that ****ing mouse)
BTW: Regex S&R is one of the simplest of the "complex edits"
Re:Just using VIM (Score:5, Insightful)
Re:Just using VIM (Score:2, Insightful)