0

I'm trying to copy text from vim into my clipboard. I'm aware that this only works in certain circumstances, but I was able to do so twice so far, so it must be an issue with my method. Unfortunately, on both occasions I immediately forgot what method I had used to do so.

Here are methods I've tried which do not work (for these directions, assume that I don't release a key until it says I do):

Method 1:
1) Press shift key
2) Press v key
3) Release shift key
4) Press down-arrow key until desired
5) Press shift key
6) Press equals key (this is + when shift is pressed)
7) Release shift key
8) Press y key
9) Release equals (+) key
Result: Text not copied.

Method 2 (doesn't change until step 7):
1) Press shift key
2) Press v key
3) Release shift key
4) Press down-arrow key until desired
5) Press shift key
6) Press equals key (this is + when shift is pressed)
7) Release shift key
Result: Before I have time to press y, indention is lost, and text is no longer highlighted.

  • If you are running vim in a terminal window, the same one that bash runs in. Then you can use its cut, paste. For Konsole you need ctrl-shirt-x, there x is c,v or x. (It does this to avoid conflict with shell and other programs that are running in the terminal). If you are running it X11 (kde, gnome, unity, cinnamon, fvwm, twm, etc. most Gnu/Linux distros, for the windowing system.) then you can press middle mouse button to paste previous selection. – ctrl-alt-delor Apr 15 '15 at 8:56
2

By default, select the text and then you can use "+y

See the help for the clipboard, :h clipboard.

  • 1
    Note: this only works if Vim is compiled with clipboard support: vim --version | awk '/+clipboard/ {print "yes"}' – jasonwryan Apr 15 '15 at 9:42
  • @zer0rest; Is that terminating " a typo? (In my vim version it's certainly not needed. The leading " defines a cut-buffer for the y command for the special [clipboard-]buffer +.) – Janis Apr 15 '15 at 9:47
  • @Janis yes it was a typo, fixed it. Thanks. – zer0rest Apr 15 '15 at 9:48
1

If you are using gvim you can use the menu: Edit->Copy. If you are using the console version of vim you can use the commands that gvim explicitly notes besides the menu entries; in your case it's "+y. So mark any text with the visual commands, V, v, or Ctrl-V, and then type "+y to put the marked region into the copy/paste buffer.

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.