76

I am running into several problems because vim's tabs are, for the lack of a better term, god awful. I want to start using multiple Gnome tabs instead, each with a different instance of vim. Everything should work fine, however, only the system buffer + can be used to share text. This makes all the commands two key strokes longer:

y y becomes " + y y

y w becomes " + y w

d ' k becomes " + d ' k

This is especially so when one considers that a simply yank/paste operation like so

y y p

becomes

" + y y " + p

Is there anyway to instruct vim to always use the system clipboard(s)?

EDIT see Here for more information on using multiple instances of vim across Gnome Terminal Tabs

Community
  • 1
  • 1
puk
  • 14,848
  • 25
  • 101
  • 181
  • 2
    whoever voted to close this, could you please clarify why you think this is not a good question. – puk Jan 06 '12 at 12:34
  • Can you explain why you don't like vim's tabs? Also, some people do not recommend to have more than one vim instance: [One Vim ... just one](http://vimeo.com/4446112) – mMontu Jan 06 '12 at 15:46
  • @mMontu I don't want 1 bufer/tab, but I still want to be able to group my buffers in different tabs. Vim does not allow this. All buffers are global. I discuss it here http://stackoverflow.com/questions/8756459/is-there-any-plugin-way-to-manage-multiple-projects-in-vim – puk Jan 07 '12 at 01:34
  • 1
    @puk: Why the need to call Vim's tabs "godawful" or "useless" just because they don't fit your idiosyncratic workflow? They're obviously useful; a huge number of people use and (enjoy using) Vim's tabs to make editing easier. Having said that, it would be an interesting project to write a plugin that adds functionality you describe in other SO question. E.g., each tab could have a `t:buffers` variable to hold buffer list for each tab and a `tabbuffers` navigation and other operations could be created with restriction to buffers only in a tab's `t:buffers` list. – Herbert Sitz Jan 07 '12 at 06:01
  • 2
    No it is true Vim does not just fit into what is now the standard workflow with out some nudging and the problems are in fact God awful to people who learned programming after things stopped being really really god awful. – Heavy Gray Jan 26 '12 at 05:20
  • possible duplicate of [How to make vim paste from (and copy to) system's clipboard?](http://stackoverflow.com/questions/11489428/how-to-make-vim-paste-from-and-copy-to-systems-clipboard) – LondonRob Jun 02 '15 at 12:03

3 Answers3

98

I found a solution to my problem here. If you add the following to your .vimrc file

set clipboard=unnamedplus

Everything you yank in vim will go to the unnamed register, and vice versa.

puk
  • 14,848
  • 25
  • 101
  • 181
  • 3
    I already gave you this answer in one of your previous questions. – romainl Jan 06 '12 at 13:11
  • I didn't consciously steal it from you. I got the inspiration to go look for this solution from a similar solution I saw here http://stackoverflow.com/a/1372546/654789 – puk Jan 06 '12 at 13:18
  • @romainl sorry about that. I actually read it, but it looked so cryptic at first that I ignored it. – puk Jan 06 '12 at 13:41
  • 14
    Or "set clipboard=unnamed" on Windows machine. – zbstof Jan 26 '12 at 14:23
  • 1
    Note that this is not a perfect solution, if you copy a line outside of vim, it's not the same as yanking `yy`, so if you paste it `p` it will get pasted in place, not on the next `p` or previous `P` line – puk Feb 09 '12 at 18:54
  • @puk you echo my sentiment. I have gotten used to just specifying the register. On occasion I even just `:let @+=@"` or similar – sehe Jan 30 '13 at 20:55
  • @sehe what does `:let @+=@` do? – puk Apr 15 '13 at 16:24
  • @puk nothing! `:let @a=@b` assigns the contents of _register_ b to _register_ a, though. Next, _register_ `+` is the X clipboard and _register_ `"` is the _unnamed register_ (used by default) – sehe Apr 15 '13 at 17:12
  • 11
    I believe you can use both at the same time, like: `set clipboard=unnamed,unnamedplus`. Mind you VIM has to be build with +X11, +clipboard and +xterm_clipboard. On windows it goes like this by default, I suppose. – Alex Mar 04 '14 at 10:11
  • On Arch-derivatives, you get the clipboard enabled CLI `vim` when installing `gvim` or another GUI version of `vim` (see [note](https://wiki.archlinux.org/index.php/Vim#Installation)). – joelostblom Dec 29 '15 at 12:27
  • While this is the correct solution, it is confusing because it uses the term "unnamed register" wrong (or at least in a confusing way). The unnamed register is `"`, and that's where things you yank/delete go by default without any configuration. Setting the `unnamedplus` option makes it so that everything that goes to the unnamed register also goes to the `+` register (i.e., the system clipboard) and vice versa. – Soren Bjornstad Dec 13 '19 at 16:08
5

By the way, if you just want to use the terminal's native copy/paste handling, suggest setting

:se mouse-=a

and just doubleclick/rightclick as you're used to in your terminal.

That said, I love vim split windows and the fact that you can use the mouse to drag window dividers/position the cursor (heresy!). That requires mouse+=a... (and will work over ssh/screen sessions as well!).

I'm used to doing things like this instead:

:%retab|%>|%y+|u

and have commands like that on recall. Note that the "+ register is coded in the command line. To copy the last visual selection to the clipboard,

:*y+

or

:'<,`>y+ 
sehe
  • 328,274
  • 43
  • 416
  • 565
  • can you please explain in a little more detail what `:se mouse-=a` does. Personally I'm not a big fan of the windows, I prefer the buffers. Buffers > windows >>>tabs – puk Jan 06 '12 at 12:48
  • @puk: I've started to appreciate windows for diffmode + quickfix. I started to appreciate tabs for multiple diff-sets (e.g. `:tabedit a|vert diffsplit b`). I do use `:set guioptions=agim switchbuf=usetab`. To remove the UI suckiness and slowness – sehe Jan 06 '12 at 13:27
  • having done what you suggest for a long time, I highly recommend puk's answer from above: `set clipboard=unnamed[plus]` – Milimetric Jan 30 '13 at 18:58
  • @Millimetric I'm set in my ways (I've come to rely on separate clipboards and hate non-standard settings in my vim - too many different systems). ***But***: on your recommendation, I will give it a whirl for a good few weeks. Cheers – sehe Jan 30 '13 at 20:54
2

Possible workaround:

"Ctrl-c to copy in + buffer from visual mode
vmap <C-c> "+y

"Ctrl-p to paste from the + register in cmd mode
map <C-v> "+p

"Ctrl-p to paste from the + register while editing
imap <C-v> <esc><C-v>
Vincenzo Pii
  • 16,001
  • 8
  • 35
  • 48
  • 2
    I thought about that, but then you'd need a new shortcut for `yw`, `y{`, `y}`, `y%`, `D`... – puk Jan 06 '12 at 11:58
  • 1
    I found a keyboard with just enough buttons http://rlv.zcache.com/piano_organ_keyboard_birthday_greeting_card-p137438190127093559zvjk9_400.jpg – puk Jan 06 '12 at 12:06
  • 1
    If you're going to use this solution, consider using vnoremap, noremap, and inoremap respectively. – Kimball Robinson Nov 08 '13 at 20:49