A Few Quickies (Not Necessarily Vim-Specific)

We now offer several techniques—some of which are offered by basic vi as well as Vim—that are worth remembering and having handy:

A quick swap

A common typing error is to enter two characters in the wrong order. Position the cursor over the first wayward character and type xp (delete character, put character).

Another quick swap

Got two lines you’d rather swap? Position the cursor on the top line, and type ddp (delete line, put line after current line).

Quick help

Don’t forget about Vim’s built-in help. A quick tap on the F1 function key splits your screen and displays the introduction to the online help.

What was that great command I used?

In its simplest form, Vim lets you access recently executed commands by using the arrow keys in the command line. Moving up and down with the arrow keys, Vim displays recent commands, any one of which you may edit. Whether or not you edit a command from Vim’s history, you can execute the command by pressing the ENTER key.

You can get even more sophisticated by invoking Vim’s built-in command history editing. Do this by entering CTRL-F on the command line. A small “command” window opens up (with the default height of 7) in which you can navigate with normal Vim motion commands. You can search as if in a normal Vim buffer, and make changes.

In the command edit window, you can easily find a recent command, modify it if necessary, and execute it by pressing ENTER. You can write the buffer to a filename of your ...

Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.