If you’ve spent any time at all on this site then you know that VIM is my preferred text editor. Even though I’ve been using it for years I still learn something new about the editor from time to time. Here is something that I just figured out a couple of weeks ago. It turns out VIM provides a simple way to repeat exactly what you last did. By simply pressing the period key, VIM will repeat whatever command -or- text you last entered.
For example, lets say you’re editing an HTML file that has a list of links. Before each link you want to add a generic image. You could do this a few ways; type in the text each time, use a search and replace or copy and paste. Using period is just one more method to add to your toolbox. To use this trick, enter INSERT mode by pressing i. Enter in the text you want to enter before each link (or whatever it is you need to repeat a few times) and when you’re done press ESC. Move to the next line and press the period key. Whatever you typed previously will be inserted to the right of the cursor. You can do this as often as you like but as soon as you delete a letter, line, insert different text or whatever the “period key” shortcut will begin to do that action instead.
Another way to use this is if you’re deleting lines of text over and over. Say you want to delete 10 rows of text at a time until you’ve deleted what ever it is you need to delete. You could press d 10 down arrow and then each time you press the period key you’ll repeat the same action.