I was trying to copy paste something from vim to another application and also, from that application to vim using right click with mouse and then copy and paste (or with Ctrl+v and Ctrl+c and also tried the Command version for mac OSX, obviously.). However, when I try doing it, it only copies the first word when I do it from vim or when I copy from the application to vim, it copies everything, but inserts strange tabs and spaces. I think this happened when I decided to set my mouse on in the terminal. As in:

:set mouse=a

I have that line on my .vimrc file on iTerm (mac os x). Though, is it possible to make my copy paste with other applications that are not in vim not to break with the mouse=a on? Or is it at least possible to set my mouse off while I do the copy paste? I did :help mouse but the comments were not useful for me. I would paste them here but... my copy paste tool is broken!

I did try :set mouse! and :set mouse=a! but these did nothing useful... :(

Additional info of my environment:

I am also using tmux most of the time, though, I tested this error/bug without a tmux session, thats why I posted this mainly as a vim question.

  • 4
    I can tell you that vim is capable of yanking to the Primary Selection just fine using the y verb. I don't know why you wouldn't just use that. – HalosGhost Jun 27 '14 at 19:44
  • 1
    I wouldn't do that because I don't know how to do that I guess, apologize for my incompetence. I didn't even know that existed until you mentioned it. Please share your knowledge! :) – Pinocchio Jun 27 '14 at 20:07
  • Is this macvim? – Patrick Jun 28 '14 at 0:00
  • no it is not its just iTerm (as I mentioned on the question, but good question though). – Pinocchio Jun 28 '14 at 1:17
  • 3
    @Pinocchio - take a look here: How to make vim paste from (and copy to) system's clipboard?. – slm Jun 28 '14 at 12:10

11 Answers 11


mouse=a prevents the ability of copying and pasting out of vim with readable characters.

Change mouse=a to mouse=r and that should fix your issue with that.

one thing I am wondering is, are you changing the config file for your vim with the mouse set to mouse=a?

orignal answer ^

If mouse=r doesn't give you all the copy past options change it to mouse=v

Both mouse=r and mouse=v have the same functions you are needing, but depending on the vimrc you are using one will work better then the other.

| improve this answer | |
  • also have you tryed highlighting the the text and use you mouse middle button to past into another place. that tends to work better when tryng to Ctrl+v and Ctrl+c – bgrif Jul 3 '14 at 15:31
  • I don't know what your question means: one thing I am wondering is, are you changing the config file for your vim with the mouse set to mouse=a? You mean if I have :mouse=a on in my .vimrc file? I do have :mouse=a in my .vimrc file file. – Pinocchio Jul 3 '14 at 15:57
  • 1
    just --with-x=yes? I do not need to put :set --with-x=yes mouse=a or something? Could you clarify what you mean? – Pinocchio Jul 7 '14 at 14:57
  • 1
    Let me research if you need to combine --with-x=yes to set mouse=a. When i was reading up on it all i saw was it was by itself in the config file. But it could be different so I want to make sure that I tell you the right thing that will work for you. – bgrif Jul 7 '14 at 15:06
  • 1
    Thanks a lot, this suggestion work like a charm with mouse=v – Pamungkas Jayuda Mar 11 '19 at 12:17

For OS X users: To copy paste with mouse=a use alt instead of Shift to selec the text. Then cmd-c and cmd-v work as expected.

Found this answer here https://stackoverflow.com/a/4608387/671639 after a lot of googling.

| improve this answer | |
  • 1
    You are God...... :') – omerjerk Dec 14 '16 at 6:54
  • 1
    the only thing that worked for me, thanks! – Don May 23 '17 at 15:10
  • 5
    For me on OSX works "fn" instead of "shift" or "alt". – ssasa Sep 10 '17 at 14:17
  • Setting mouse=v worked for me with straight cmd + c – nattyddubbs Jul 24 at 13:36

From https://stackoverflow.com/questions/4608161/copy-text-out-of-vim-with-set-mouse-a-enabled/4608387

Press 'shift' key while selecting with the mouse. This will make mouse selection behave as if mouse=a was not enabled.

This works and has been verified by reviewers of stack-overflow who have accepted this as answer :)

| improve this answer | |

Had the same problem: could not highlight using the mouse so could not copy and paste from VIM in a terminal session to Windows document and browser: Did the following and it now works:

: set clipboard=unnamedplus
: set mouse=r
| improve this answer | |

Bharath's solution, pressing Shift while copying, will do it, but it will copy more than what you'd like to copy in-case of numbering or hash comments.

One way to do so even with mouse=a is use visual mode by pressing V for single cursor or Shift+V for full line highlight, and you can move up or down with arrows and use Y to copy or D to cut and that should work.

| improve this answer | |
  • @Anthon, Will do, Thanks for the clarification. – amrx Apr 2 '15 at 14:02
  • 1
    I rephrased your self-pronounced comment to make it more like an answer that way the mods will probably leave it as is (and you might gain some reputation on it so you can comment). If the original had been a more minor correction, commenting would have been more appropriate. – Anthon Apr 2 '15 at 14:15

Refer: http://vimdoc.sourceforge.net/htmldoc/options.html

Look at Note section at the bottom of the reference:
When enabling the mouse, the mouse buttons can still be used by keeping the shift key pressed. This includes copy paste using mouse buttons.

*'mouse'* *E538*
'mouse'         string  (default "", "a" for GUI, MS-DOS and Win32)
            {not in Vi}
    Enable the use of the mouse.  Only works for certain terminals
    (xterm, MS-DOS, Win32 |win32-mouse|, QNX pterm, *BSD console with
    sysmouse and Linux console with gpm).  For using the mouse in the
    GUI, see |gui-mouse|.
    The mouse can be enabled for different modes:
        n   Normal mode
        v   Visual mode
        i   Insert mode
        c   Command-line mode
        h   all previous modes when editing a help file
        a   all previous modes
        r   for |hit-enter| and |more-prompt| prompt
    Normally you would enable the mouse in all four modes with:
        :set mouse=a
    When the mouse is not enabled, the GUI will still use the mouse for
    modeless selection.  This doesn't move the text cursor.

    See |mouse-using|.  Also see |'clipboard'|.

    Note: When enabling the mouse in a terminal, copy/paste will use the
    "* register if there is access to an X-server.  The xterm handling of
    the mouse buttons can still be used by keeping the shift key pressed.
    Also see the 'clipboard' option.
| improve this answer | |
  • 1
    Thanks for contributing that reference, but, does it answer the question? If so, can you identify the part of the quote that does so, presenting a summary of the actual answer? – G-Man Says 'Reinstate Monica' Feb 23 '15 at 18:36

On my Mac, what helped were those two things:

  • :set mouse-=a
  • fn+click (instead of shift or alt)
| improve this answer | |

You can use y to copy(yank) and p to paste even with :set mouse=a set in ~/.vimrc. Use v+arrow keys to highlight the text. To copy an entire line quickly, use shift+y.

| improve this answer | |

Use these two lines below in your ~/.vimrc to use all nice features of a gui-mouse and paste into system clipboard using y (yank key) if you don't really need any additional clipboard buffers:

set mouse=a
set clipboard=unnamed
| improve this answer | |

As for the second part of your question where in you specified that when pasting from other applications to vim it adds tabs/spaces. Try adding this to your ~/.vimrc set paste or in vim before pasting in normal mode press "shift" + ":" and type "set paste"

| improve this answer | |

Two things to add:

  1. Be aware many times set mouse=v won't work as expected depending on the other directives you have set before or after in your .vimrc file, it also depends on which terminal you are running vim from;
  2. I would recommend to keep mouse=a so you have all the mouse mode enabled at the same time and use the trick proposed by @BHS to highlight text while pressing the Shift key when you need to paste the highlighted text using the middle mouse button (Copying text outside of Vim with set mouse=a enabled).
| improve this answer | |

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.