简体   繁体   中英

How do I copy and paste from bash to vim and vice-versa using only the keyboard?

Using this command:

http://www.hypexr.org/bash_tutorial.php#vi

I'm able to use vim commands in the bash. But, what I'd like to do is copy and paste from that (bash) into vim and vice-versa.

I know there are other posts on here using the middle mouse button, but I use putty to connect to linux boxes, and the middle mouse performs a selection, just like the left click drag.

I'm not looking for something that will modify my windows clipboard. Selecting in vim is useful for transfering stuff to and from windows, but I'd like a solution that will work both through putty and using a direct terminal.

Thanks in advance...

I use the copy&paste feature in screen . ctrl-[ to enter copy mode and ctrl-] to paste. There are different buffers and the ability to dump to a file. It's pretty powerful. The default is to copy lines, but you can curtail by columns join display lines into a single copied line (and other options). And since you would likely already be in screen when you run vim, you would have the paste buffer available. I also have hooks to copy the buffer to/from the X clipboard.

I don't know if that can help you, but I have installed a utility called xclip, which shares the X11 clipboard with VIM. I mainly use it to copy and paste between instances of VIM running in different terminal windows.

I typically use xclip with the following mappings, which keep a very similar behaviour to the usual yank and paste commands, but using the clipboard:

nmap `yy    :.w !xclip<CR><CR>
vmap `y     :w !xclip<CR><CR>
nmap `p     :.r!xclip -o<CR>
nmap `P     :.-r!xclip -o<CR>

您可以使用ctrl + ins进行复制,并使用shift + ins进行粘贴,在vim和bash中从剪贴板复制/复制到剪贴板。

Use the * (or + in X Windows) registers to reference the system clipboard. Anything yanked-to or pasted-from those registers can be used to cooperate with other applications:

Cut/Copy examples

"*yy : copy current line to the system clipbard

gg"*yG : copy current file to the system clipbard

"*dd : cut current line to the system clipbard

etc, etc


Paste examples

"*p : paste the system clipbard

Or in insert mode:

i Ctrl + r *

Or

i Ctrl + r Ctrl + p *

(the last one pastes withouth formatting, useful to avoid those ugly pastes from the OS clipboard where each indented line appears more and more shifted)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM