0

I'd like to be able to copy and paste using the system clipboard without having to toggle paste mode every time. Is there a way to do that?

If it matters at all, I'm using vim from the terminal on a Mac.

babaloo
  • 435
  • 5
  • 24
  • Seems repeated topic: http://stackoverflow.com/questions/11489428/how-to-make-vim-paste-from-and-copy-to-systems-clipboard – Kir Chou Oct 13 '14 at 06:09
  • Do you mean you want to be able to safely paste or copy raw text in the terminal without having to [`:set paste`](http://vimdoc.sourceforge.net/htmldoc/options.html#%27paste%27) beforehand and `:set nopaste` afterwards? Or do you mean you want commands like [`y`](http://vimdoc.sourceforge.net/htmldoc/change.html#y) and [`p`](http://vimdoc.sourceforge.net/htmldoc/change.html#p) to copy to and paste from the system clipboard by default? – Rory O'Kane Oct 13 '14 at 06:37
  • Like on *every* other UNIX-like system, the default Vim doesn't have built-in clipboard support so you must install a proper one. On Mac OS X, your best bet is MacVim. – romainl Oct 13 '14 at 07:02

1 Answers1

3

If you mean you want to be able to safely paste or copy raw text in the terminal without having to type :set paste beforehand and :set nopaste afterwards, you have a few options.

  • Set the 'pastetoggle' option. See :help 'pastetoggle', which gives this usage example:

    :map <F10> :set paste<CR>
    :map <F11> :set nopaste<CR>
    :imap <F10> <C-O>:set paste<CR>
    :imap <F11> <nop>
    :set pastetoggle=<F11>
    
  • Create mappings for :set paste and :set nopaste, like in the above code.

  • Install the plugin unimpaired.vim. It provides mappings yo and yO that :set paste, do o or O, and then automatically :set nopaste when you exit Insert mode.

If you mean you want commands like y and p to copy to and paste from the system clipboard by default, then just see the existing question How to make Vim paste from (and copy to) system’s clipboard?

Community
  • 1
  • 1
Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
  • I mean that I'd like to be able to paste text into vim using the system keyboard without having to toggle paste mode before and after I paste. – babaloo Oct 14 '14 at 19:05