Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to copy something from vim editor to shell command line

I intend to copy something from vim editor to shell command line. I have tried many ways, but I find all of them only work when in the same vim editor. My need is to copy and paste between vim editor and shell command line. That's, vim -> shell

PS: I am using putty.

EDIT:

BTW, what if just copy something from vim editor and paste it to terminal both in a unix/linux box?

ATTENTION:

output of :echo has("X11") in vim is 0, so my system does not support X11!

like image 767
dj199008 Avatar asked Feb 16 '14 11:02

dj199008


People also ask

How do I copy and paste a code in vim terminal?

To copy from a terminal window press CTRL-W N (This is a capital N)1 or CTRL-\ CTRL-N (this is not a capital N) to get into normal mode. From there you can use all usual vim commands to copy and paste stuff.

How do I copy outside of Vim?

Shift-v selects the entire line. In Vim, Copying is done using the y or "yanking". To copy selected text to system clipboard type "+y in Normal Mode. Now you can paste it anywhere else using Ctrl-v .


2 Answers

If your vim version >= 7.3.74, you can set the vim to use the system clipboard by default by adding a line to your .vimrc:

set clipboard=unnamedplus

for the detail, see this link. Then you use the y(ank) command in vim, the content is in the system clipboard.

EDIT:
this solution and the "*y solution require the Vim that has clipboard support. Since you're lack of that, use cat/grep/less/tail... to extract the text you want to copy.

like image 58
jfly Avatar answered Sep 25 '22 22:09

jfly


" + y to yank text in vim, then ctrl + shift + v to paste in the terminal.

like image 22
Jake Sellers Avatar answered Sep 24 '22 22:09

Jake Sellers