Ever since I started using Vim, there is always some moments that I knew I was doing in not-so-Vimish fashion. Pasting the same yanked text over and over is one of them, and I never figured out how to do it correctly until now.
When you yank something or delete something for pasting that text multiple times, it wouldn’t be any problem for you. But if you need to replace some texts with that same yanked text, then it might be. Note that this is a case you don’t use substitutions, because the replaced text might not be regular. You have to manually select and paste to replace.
After reading :help put-Visual-mode and :help registers, I learned that every time you p or P or d on a selection, the unnamed register "" will be replaced with the selected text, which is also used for p, therefore, next time you p, it will be the previous selected text and that’s not what we want.
The solution is to paste with the numbered register "0, which contains most recent yanked text. Since we only yank once, therefore its content is always what we want to paste. Also, the numbered register "1 contains most recent deleted text. So if you delete something and want to continuously paste that deleted text on selections, that’s the register you want to use.
If you want to paste (put) multiple texts, then it might be better that you store them in a named register "a to "z. Here is the rough keypresses:
v -> y -> v -> "0p -> v -> "0p -> ... <- pasting from most recent yanked text v -> d -> v -> "1p -> v -> "1p -> ... <- pasting from most recent deleted text v -> "ay -> v -> "ap -> v -> "ap -> ... <- pasting from ... v -> "by -> v -> "bp -> v -> "bp -> ... <- yanked text v -> "cd -> v -> "ap -> v -> "ap -> ... <- pasting from ... v -> "dd -> v -> "bp -> v -> "bp -> ... <- deleted text | \--- selecting the replaced text \--------------- selecting the yanked or deleted text
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.