23

I already know that you can copy something to the a register using: (plus a yank, delete, etc. command)

"a

I also understand that you can append to the a register using:

"A

In addition I understand how to copy something to the clipboard register using:

"+

What do I type to append to the clipboard register?

My vim version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 2 2014 19:39:59) Huge version with GTK2 GUI.
Jason Basanese
  • 969
  • 1
  • 8
  • 17

4 Answers4

13

There is no normal mode command for that but you can simply append to another register and :let the clipboard register to the content of that register:

"Ay
"Ay
"Ay
:let @+ = @A
romainl
  • 40,486
  • 5
  • 85
  • 117
9

You can call setreg('+', lines, 'a'), but as far as I can tell there is no way to do that with normal mode commands. You have to use one of the upper case letter registers for that.

lcd047
  • 3,700
  • 16
  • 26
  • Just using :let @+ .= 'XXX' seems to work? – Martin Tournoij Jul 04 '15 at 06:56
  • 7
    @Carpetsmoker Yes and no. There has been a recent discussion about it on vim_dev and apparently you aren't supposed to do that, even though it may appear to work under some conditions. I presume it has to do with the register contents having a type (character / line / block), and string concatenation not doing the necessary bookkeeping. It doesn't make any difference anyway, it still isn't a normal mode command. – lcd047 Jul 04 '15 at 07:02
0

Since clipboard is being used, it is obvious that X is being used. Issue of appending to clip board regularly occurs. If you are not using Linux, following is not for you. My solution consists of two additional programs, xclip and xbindkeys. Please see the following shell script which can be bound to a desired key combination in xbindkeys. Simply select the desired text and press the key combination to append the selection to the clipboard.

#!/bin/sh
APPND=1
if [ $# -gt 0 ] ; then
   if [ $1 -eq 1 ] ; then
      APPND=0
   else
      APPND=1
   fi
fi
if [ $APPND -eq 1 ] ; then
   echo "$(/usr/bin/xclip -o -selection clipboard) $(/usr/bin/xclip -o -selection primary)"|/usr/bin/xclip -i -selection clipboard
else
   echo "$(/usr/bin/xclip -o -selection primary) $(/usr/bin/xclip -o -selection clipboard)"|/usr/bin/xclip -i -selection clipboard
fi

Note: The above script is used to either insert in clipboard before of after its contents. the corresponding entries in my xbindkeys file is

"<complete path to the script>"
  Shift+Alt+c

"<complete path to the script> 1" Shift+Alt+d

So after selection, if we press Shift+Alt+c the selection is pasted at the end of the clipboard and if we press shift+Alt+d the selection is pasted before the current contents of the clipboard. Execute permissions should be given to the script. This is a universal solution for all x applications. I have verified it in gvim also.

0

I made a keymap which I use for appending. It yanks to the '0' register which is the default for yank and then appends it to your '+' register.

vnoremap <leader>y <Cmd>call AppendYank()<CR>

function! AppendYank() normal! "0y call setreg('+', getreg('+') . getreg('0'), getregtype('+')) endfunction

declancm
  • 1
  • 1