Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: append to special registers (e.g. +)

Tags:

vim

I would like to make a shortcut to append to the register "+" (so I can do a system paste outside of Vim). For example, I would like to do "+yy to copy one line, and then "=yy to append another line to the '+' register.

I've found VIM: how to append yanked text to unnamed register and I feel like it should be easy to get what I want, but I don't understand anything of Vim script.

like image 563
Xu Wang Avatar asked Dec 31 '25 06:12

Xu Wang


1 Answers

You could choose an arbitrary register, say z, to which you do the appending dance, "zyy then "Zyy, and create a shortcut just for "exporting" that register:

nnoremap <silent> <key> :<C-u>call setreg('+', getreg('z', 1), getregtype('z'))<CR>

(Edited as per ZyX's comment.)

like image 95
romainl Avatar answered Jan 05 '26 05:01

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!