VIM Dot Command
When teaching VIM in my Linux classes many students think the dot command is, well, kind of pointless. If we can delete a character using just one key then I don’t need the dot command to repeat the edit. Or do I? Well, of course, you do that is why I am here and that is why I have this blog.
Repeats the Last Change
Although the VIM manual is not very clear on this the dot command repeat’s the last change. Yes, we can show you this with a single character deletion. Moving to any character that we would want to delete. When in normal mode, we can use x to delete a single character from where the cursor is. Just pressing the dot or period will repeat the deletion. This does not really help promote the VIM dot command. It really does a lot more than this.
When the Last Change is an Append
In the video, you will see that I have a source file with missing semi-colons at the end of lines. I cam use the A command in normal mode to take me to the end of the line and append after the last character on the line. I then add in my semi-colon and use ESC to return to normal mode. The dot command now is a macro to append to the end of a line and add the semi-colon before returning to normal mode. I just mode to each line that needs the semi-colon and use the period to repeat the last change. Pure magic.