I recorded a register and it work normally.

I mistakenly overrode that register, fortunately I already saved the pattern. It's as below:


This means I copy a block (which have _a or _a_) and paste it to two others block, then change _a or _a_ to _b, _b_ and _c, _c_.

However, when I copy this line to my new register and execute, it don't understand that it need to replace ^M with Enter. However, it stop at command line with exact whole register content.

I tried change ^M to <C-M> or <CR> or <Enter>, but they don't work also.

Please help.


Your solution is one way. But to insert something into a register from a buffer (e.g. "iy$) as you were originally attempting to do...

Literal control-characters can be entered by prepending ^V (CTRL-V). So before you yank your text into the register replace ^M (caret plus letter "M") with what you get by hitting Ctrl+V then Ctrl+M.

| improve this answer | |

You can use "ip to put the register into a buffer, edit it, then use "iy$ or similar to put it back into the register. This mostly preserves the meanings of special characters such as ^M.

| improve this answer | |

This blog http://of-vim-and-vigor.blogspot.com/2012/06/advanced-macros-in-vim-commentary.html help me to answer this question.

The content of register need to change to:


Then use

let @i = "V}y}pV}:s/_a\\(\\>\\|_\\)/_b\\1/g\<CR>pV}:s/_a\\(\\>\\|_\\)/_c\\1/g\<CR>"

After that I can use my @i register.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.