vi editing  «Prev 

Keyboard macros

In a file named text, there are two lines where you want to transpose words.

The dw command deletes the word upon, and the cursor ends up on the o in the word once.

The w command moves the cursor one word forward. The cursor is now on the word a.

The P command puts the deleted word, upon, before the cursor location. This trial runs show that the command sequence dwwP will transpose two words.

Use the :map command, you can assign the sequence dwwP to the letter V. Now typing V in command mode is the same as typing dwwP.

Here, the cursor is move to another line where you want to transpose words. The cursor is on the u of upon.

This time, you can simply press the V key to switch the two words, upon and once.