vi editing  «Prev 

Keyboard macros

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

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

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

4) 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
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.

5) 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
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.

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

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