Recording actions in Vi/Vim
How often did you accidently hit 'q' followed by some other key and saw a message that says 'recording'? Many of us don't know what it means when it says recording. Well, here is a brief explanation. You can record your actions in Vi and run the recorded sequence of actions when you need them. Let us look at a scenario.
You have the word 'my_config_file.php3' in many places in a file. You want to replace 'my' with your, change 'php3' to 'php' and add a line that says 'above line has been modified for new settings' just below the line containing the word.
The way to do this:
- In command mode, find 'my_config_file.php3' with / (pattern search). You arrive at the first match.
- Press 'q' followed by say 'a'. This means vi should start recording your actions in a record called 'a'. You should see a message 'recording' near the bottom.
- Now, carry out your editing actions. In our case, the actions are 2x,i, insert the word your, press escape, 3e, x, o, insert the new line, press escape, n to find the next match.
- Now, press 'q' again to stop recording. Your actions are saved in a record - a.
- To play the recorded actions, just use '@' followed by record-name. In our case, '@a'.
The record-name has to be a single, non-special character. Try it out yourself !
