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.

2
  • 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. Commented Apr 15, 2015 at 8:56
  • FWIW, I'm running Debian 12 and vim-gtk3, and copying/pasting to/from the clipboard or selection works in gvim, but not in vim running in konsole/yakuake. Haven't been able to figure out why yet. Commented Jun 3, 2024 at 6:15

2 Answers 2

2

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

See the help for the clipboard, :h clipboard.

3
  • 1
    Note: this only works if Vim is compiled with clipboard support: vim --version | awk '/+clipboard/ {print "yes"}' Commented Apr 15, 2015 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 +.) Commented Apr 15, 2015 at 9:47
  • @Janis yes it was a typo, fixed it. Thanks. Commented Apr 15, 2015 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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.