Copy/Pasting and Vim

I’m a vim user and I somehow completely missed this excellent feature until much more recently than I care to admit! Usually vim has its own clipboard, but it doesn’t share with the operating system. You will need a vim-gtk install, this isn’t available in really basic vim (I’m a little unclear exactly on the dependencies).

To paste between vim and something else, use the + (plus) buffer in vim. It contains the contents of your system clipboard, and you can also write to it. If you’re not already using buffers in vim, then you should probably read the excellent documentation but for a very quick start:

  • To copy something into the buffer, select it in visual mode and type "+y
  • To paste from the buffer, type "+P

I had no idea how I’d missed this really fundamental trick, so I thought I’d share!

3 thoughts on “Copy/Pasting and Vim

  1. You can also type “yy” to just copy 1 line and “p” to paste (or “2yy” to copy 2 lines). My brain has an easier time remembering that one :)

  2. Me with vim always look like this:
    $ vim file.txt
    Can’t edit, can’t do anything. Have to search on Google on how to exit. Then:
    $ nano file.txt
    Seriously, I’ll need to learn VIM basics so that my coworkers don’t make fun of me with my “pretty nano” editor ;) I just think it’s way more user friendly.

    • Nano really is much more user friendly. I spent a year stuck with vim as the only option and now I love it … if you don’t have a spare year then just use nano :)

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.