I have this command in my .vimrc:
vip:normal @g<CR>
When I set the register 'g' by typing in the buffer, like this, it works:
qg<CR>jq
If I type :registers, it shows:
--- Registers ---
"g ^Mj
After that, typing @g results in a carriage return and then the cursor moves to the next line. The ^M appears in a special color.
However, when I use the setreg command in my vimrc, if I type @g, nothing happens.
call setreg('g','^Mj')
If I type :registers, it shows:
--- Registers ---
"g ^Mj
The ^M is not in a special color.
I have the following in my .vimrc:
map <CR> :call MyFunction<CR>
The carriage return I want to store in the register is to run MyFunction. MyFunction is called perfectly as long as I fill the buffer manually rather than using setreg.
Where have I gone wrong? My platform is Linux.
You are looking for "\<cr>"
or "\r"
call setreg('g',"\<cr>j")
call setreg('g',"\rj")
or more simply
let @g = "\<cr>j"
let @g = "\rj"
For more help
:h expr-quote
:h let-@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With