Copying to clipboard in vi

683 views Asked by At

So I've looked through this question: how to copy codes in vi to clipboard and found that it is possible but requires the -xterm_clipboard to be +xterm_clipboard. Apparently the only way to resolve that issue is to find a different version of vim to use, which I am hoping to avoid. Are there any other ways to accomplish copying to the clipboard without switching to something different?

If it's relevant, I'm running Ubuntu dual-booted with windows.

I apologize if this is a stupid question, I'm still rather new to command line programming, and there's a lot of stuff to learn.

2

There are 2 answers

0
romainl On BEST ANSWER
$ sudo apt-get install vim-gnome

will replace your current Vim with one that's built with clipboard support without changing anything to your configuration files or the features you are getting used to.

0
Gordonium On

Select what you would like to copy to the clipboard. In the gif below I used ggVG to select the entire text of the file.

Now the text you want is selected. To get this into the special * register that Vim uses for the system clipboard you would type "*y.

If you combine those commands (ggVG"*y) it should yank the text of the entire file into the system clipboard (the * register). The (rather bad quality) gif below shows this command in Vim copying to the system clipboard and pasting into TextEdit.

enter image description here

Going the other way is also possible using the * register.

Copy something that you want. Load Vim and type "*p. This accesses the * register and puts (pastes) it using p. Here's a gif where I copy someting to the clipboard and then use "*p in Vim to paste it.

enter image description here