0

I recorded a register and it work normally.

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

V}y}pV}:s/_a\(\>\|_\)/_b\1/g^MpV}:s/_a\(\>\|_\)/_c\1/g^M

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.

2

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.

1

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.

1

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:

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

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.

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.