Learning the vi text editor[1] takes some effort, but experienced vi users know that after a while, using basic commands becomes second nature. It's a form of what is known as muscle memory, which in this case might well be called finger memory.
After you get a grasp of the main approach and basic commands, you can make editing with vi even more powerful and streamlined by using its customization options to create shortcuts. I hope that the techniques described below will facilitate your writing, programming, and data manipulation.
Before proceeding, I'd like to thank Chris Hermansen (who recruited me to write this article) for checking my draft with Vim[2], as I use another version of vi. I'm also grateful for Chris's helpful suggestions, which I incorporated here.
First, let's review some conventions. I'll use <RET> to designate pressing the RETURN or ENTER key, and <SP> for the space bar. CTRL-x indicates simultaneously pressing the Control key and the x key (whatever x happens to be).
Set up your own command abbreviations with the map
command. My first example involves the write
command, used to save the current state of the file you're working on:
:w<RET>
This is only three keystrokes, but since I do it so frequently, I'd rather use only one. The key I've chosen for this purpose is the comma, which is not part of the standard vi command set. The command to set this up is:
:map , :wCTRL-v<RET>
The CTRL-v is essential since without it the <RET> would signal the end of the map, and we want to include the <RET> as part of the mapped comma. In general,