The way you initialize has two flaws:
First, it is usually better to use setreg()
to set the value of a register, it is more robust than let @X =
and allows you to choose the type of the register (characterwise, linewise, blockwise)
Second, your string contains the keycode of some key (e.g. ^M
for <CR>
). I guess that you recorded your macro and tried to get what you recorded and that's what caused the problem. In your vimrc you need to write the following:
call setreg('p', "iprocess (clk, resetn)^M€kbbegin^Mif (resetn = '0') then^M")
where ^M
is not entered manually but is entered by pressing Ctrl+v then Enter this allows you to write the keycode of the key which setreg()
can then interpret properly. Note that you should do that with the others special keys like <Esc>
for example.
Edit As mentioned by @Rich in the comments using \<CR>
inside a double quoted string is arguably more robust than <C-v><CR>
.
See:
call setreg('p', "iprocess (clk, resetn)^M€kbbegin^Mif (resetn = '0') then^M")
note that the^M
should be added by pressing<C-v><CR>
in insert mode to enter the keycode of the return key. – statox Jan 26 '18 at 12:01