After enabling set mouse=a
, text copied inside of Vim will not paste outside of Vim. Does anybody know of a way to fix this?
Here, selecting text with t
I accidently explained how to switch off set mouse=a
, when I reread the question and found out that the OP did not want to switch it off in the first place. Anyway for anyone searching how to switch off the mouse (set mouse=
) centrally, I leave a reference to my answer here: https://unix.stackexchange.com/a/506723/194822
Add set clipboard=unnamed
to your .vimrc
. So it will use the clipboard register '*' instead of the unnamed register for all yank, delete, change and put operations (note it does not only affect the mouse).
The behavior of register '*' depends on your platform and how your vim
has been compiled (or if you use neovim
).
If it does not work, you can try with set clipboard=unnamedplus
, but this option only makes sense on X11 systems (and gvim therefore).
Compilation settings that vim was compiled with, are part of the issue. vim --version
shows these.
In OSX, the default vim has -clipboard
But you need +clipboard
On osx you can and apparently generally should, use macvim. You can do brew cask install macvim
That one has +clipboard
.
Them you'll have two vims.
~$ ls -l /usr/bin/vim <--- default vim
-rwxr-xr-x 1 root wheel 1745984 15 Jul 2017 /usr/bin/vim
~$ ls -l /usr/local/bin/vim <-- macvim, installed recently via that mentioned brew line.
lrwxr-xr-x 1 apple admin 42 16 May 23:32 /usr/local/bin/vim -> /Applications/MacVim.app/Contents/bin/mvim
~$
running vim will run macvim 'cos /usr/local/bin
should be before /usr/bin
in the path, though you can check with which vim
.
running vim(to run macvim), is fine but you may want to map vi to macvim 'cos otherwise running vi stays at the default vim! You can rewrite or delete(with rm) and recreate the vi sym link, with ln. And to do that without an 'operation not permitted" error, you have to (temporarily) disable SIL. https://apple.stackexchange.com/questions/208478/how-do-i-disable-system-integrity-protection-sip-aka-rootless-on-macos-os-x .
macvim has +clipboard
as shown by vim --version
Here is a working ~/.vim/vimrc
with just the required lines.
:set mouse=a
:map <leader>c "+y
:map <leader>v "+p
The default leader key is backslash.
I read a suggestion that one should use the leader key.. (certainly control has many keys already in use, so the suggestion was to not use control. I don't know if that applies to command key too, but anyhow).
With that mentioned mapping, \c
will do "+y
which will copy from the register known as +, to the clipboard. And \v
will paste from the register known as +.
So that's a copy/paste that works between windows.
Another OS may require "*
rather than "+
On OSX use fn instead of shift.
In Ubuntu, it is possible to use the X-Term copy & paste bindings inside VIM (Ctrl-Shift-C & Ctrl-Shift-V) on text that has been hilighted using the Shift key.
Holding shift while copying and pasting with selection worked for me