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?
相关问题
- Emacs shell: save commit message
- How to change the first two uppercase characters o
- Insert text into current buffer from function
- Hot reload on save
- Substituting zero-width match in vim script
相关文章
- 如何让 vim 支持 .cshtml 文件的代码高亮
- Auto-save in VIM as you type
- How can I use gcc's -I command to add recursiv
- Vim: overloaded mapping for multiple modes
- vi editor is not responding
- How to use relative line numbering universally in
- How to copy the value of a vim option to a registe
- E185: Cannot find color scheme*
My most common examples are changing the indent level of text
or just re-doing a particular text change like inserting
(char *)
in front of several variables:(or whatever)
For me the dot command was hit or miss at first until I started recording macros with any frequency. The trick to recording useful macros is to represent the problem as repeatable steps. Sometimes the dot is the only thing that will do or at least makes the problem much easier.
Also, using the dot command will force you to use certain commands that you may have not needed as much before such as: cw ct; ci" ca) since they collapse the delete/change of the text into one "action" that is repeatable by dot.
Also, in addition to dot there is also ; which I use much less frequently but when i do its very useful which repeats the last text motion. Not that useful for things such as w and b but for things like f; its a nice little trick.
All the other answers provides good examples, I just want to add that
dot
is great because in a way it is an automatic macro for your last key combination that is only one key away.While macro are great, they are a bit cumbersome to use, while the
dot
is always available, even if less powerful.Now, with the cursor in the first line:
A<bs><cr>{<cr><cr>}<cr><esc>
. Now hitj.j.
andI use
dw....
fairly often to delete a series of words without needing to mentally count them first. In that example,5dw
is fewer characters, but I think I am about 3ms faster using the dot command to just repeat thedelete word
over counting them.Edit I was just now doing some editing and realized there is another situation that I use the dot command a fair amount. I would imagine there is a much simpler way of handling this type of thing in Vim, but the dot command helps out with the following and similar situations. The following is basically an example of "I did something once, now I want to repeat it a few more times." I was writing a new test (in C) and needed to embed into it a string constant representing an SQL script that I copied from another place. The original multiline (7 line) script was not enclosed in double quotes, so I did this:
Like the previous poster, I often use it when deleting:
dw...
dd...
And when repeating an action on multiple lines:
iSomeText:[Esc]j.j.j.