80

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

6
  • 2
    whoever voted to close this, could you please clarify why you think this is not a good question.
    – puk
    Jan 6, 2012 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
    – mMontu
    Jan 6, 2012 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 stackoverflow.com/questions/8756459/…
    – puk
    Jan 7, 2012 at 1: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. Jan 7, 2012 at 6: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. Jan 26, 2012 at 5:20

3 Answers 3

103

I found a solution to my problem vim.wikia.com: Accessing the system clipboard. If you add the following to your .vimrc file

set clipboard=unnamedplus

for linux or

set clipboard=unnamed

for Windows.

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

7
  • 3
    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 9, 2012 at 18:54
  • 2
    @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, 2013 at 20:55
  • @sehe what does :let @+=@ do?
    – puk
    Apr 15, 2013 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, 2013 at 17:12
  • 12
    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 4, 2014 at 10:11
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+ 
4
  • 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 6, 2012 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 6, 2012 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, 2013 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, 2013 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>
3
  • 2
    I thought about that, but then you'd need a new shortcut for yw, y{, y}, y%, D...
    – puk
    Jan 6, 2012 at 11:58
  • 1
    I found a keyboard with just enough buttons rlv.zcache.com/…
    – puk
    Jan 6, 2012 at 12:06
  • 1
    If you're going to use this solution, consider using vnoremap, noremap, and inoremap respectively. Nov 8, 2013 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.