The last “Power Tools” column described two — extensive help and windows — of the many things that make vim better than (but stll compatible with) original vi. (You can get a list of more “most interesting” vim additions by typing :help vim-additions from within vim.) This month, let’s dig into some of vim’s programmable features: improvements in key mapping, a scripting language, and built-in and user-defined functions. Put down your mouse and get ready to roll!
Be Incompatible
By default, vim acts as much like vi as it can, modulo the worst vi “bugs.” However, some features require vim to act unlike vi. vim automatically “improves” itself if it finds a .vimrc file in your home directory. Otherwise, you can make vim act like vim by typing:
:set nocompatible
If you’re following along from your keyboard, please run that command now.
Key Mapping Plus
Original vi lets you make simple “programs” by mapping one or more keys to run a sequence of commands. For instance, the following command maps the two-key sequence \d to surround the current word with double quote (”) characters:
:map d i"^[Ea"^[
After defining this keymap, pressing \ followed quickly by d inserts a double quote to the left of the cursor (i”), returns to command mode (^[, which represents an ESC character), moves…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: