I use VIM pretty regularly now but I never use the dot (.) command to repeat the previous action. I keep reading about how awesome it is but I never see any real world examples that make sense to me and the way I code in VIM. What are some real world examples that show how awesome the dot (.) command is?
Share
Here are some actions that I do with the dot command:
:%s/\<word\>/replacement/gcis*on the word, thencereplacement<esc>and then repeatn.. This is nice if you have two or three occurrences of your word. If you have several words that you want to replace, then go to the next word, hit*and againn.<Ctrl-V>jjj<.....or insert spaces at the front:<ctrl-v>jjjI<space><esc>....ddordw, the dot command will delete another line/wordA magical thing that happens with the dot command is that if it repeats a command that used a numbered register, it will use the next numbered register (see
:help redo-register).Explanation: If you did
ddon 9 lines and want to restore them in the order in which you’ve deleted them, then do:"1P......... Note that registers 1 to 9 are Vim’s delete-ring."1Pwill insert before the cursor the last deleted text,"2Pwill then insert prior-to-last deleted text, and so on.