Copying text outside of Vim with set mouse=a enabled

0 votes
asked Jan 5, 2011 by lyuba

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 the mouse turns on visual mode and disables the Copy option in the popup menu:

enter image description here

7 Answers

0 votes
answered Jan 5, 2011 by josh-lee

Use "+y. You shouldn’t be using the terminal’s copy command anyway, because that copies what the terminal sees instead of the actual content.

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.

0 votes
answered Jan 14, 2013 by marc-gibbons

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.

0 votes
answered Jan 11, 2014 by avishek

In ESC mode, when set mouse=a, select the text using mouse. This would enable the visual mode in vim. Then you can press 'y' to yank the selected text and 'p' to paste it wherever you want. This happens only within vim.

0 votes
answered Jan 23, 2014 by amitesh-anand

If you are using, Putty session, then it automatically copies selection. If we have used "set mouse=a" option in vim, selecting using Shift+Mouse drag selects the text automatically. Need to check in X-term.

0 votes
answered Jan 21, 2016 by reor

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.

Note for Multiline with line numbers:

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.

0 votes
answered Sep 15, 2017 by ssasa

On OSX use fn instead of shift.

0 votes
answered Sep 15, 2017 by nefeline

Instead of set mouse=a use set mouse=r in .vimrc

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter