We can use the “+p and <Ctrl+r>+ in normal and command mode, respectively. However, it might be more convenient if we use the <Ctrl+Shift+v> hotkey since it does the same thing as “+p. Similarly, <Ctrl+Shift+c> will yank the text into the + register to be available for pasting outside of Vim.
Press shift while selecting with the mouse. This will make mouse selection behave as if mouse=a
was not enabled.
Note: this trick also applies to "middle button paste": if you want to paste in vim text that was selected outside, press shift while clicking the middle button. Just make sure that insert mode is activated when you do that (you may also want to :set paste
to avoid unexpected effects).
OS X (mac): hold alt/option while selecting (source)
Use ", +, y after making a visual selection. You shouldn’t be using the terminal’s copy command anyway, because that copies what the terminal sees instead of the actual content. Here is what this does:
+
for the next delete, yank or put. The register named +
is a special register, it is the X11 clipboard register. (On other systems, you would use *
instead, I think, see :help clipboard
and :help x11-selection
)You could map it like this:
:vmap <C-C> "+y
And then highlight something with the mouse and press Control-C to copy it.
This feature only works when Vim has been compiled with the +xterm_clipboard
option. Run vim --version
to find out if it has.
Instead of set mouse=a
use set mouse=r
in .vimrc
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.
Another OSX-Mac option is to uncheck View->Allow Mouse Reporting
(or press ⌘-R to toggle it.) This allows you to toggle between mouse interaction and mouse selecting, which might be useful when selecting and copy/pasting a few bits because you don't have to hold a modifier key to do it.
I usually have line numbers enabled so this will also copy the line numbers if you select multiple lines. If you want to copy multiple lines without the line numbers disable the numbers with :set nonu
and then you can :set nu
to re-enable them after you're done copying.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With