I am using putty to connect a remote host and editing via vim. I meet a trouble when I try to paste something to vim. That's, I copy something to clipboard in my local host and want to paste it to the vim in the remote host. How to do that?
ps: I am using putty! So, I open a vim window via putty. The very need is that I want to copy something in my local host and paste it to the vim editor opened by putty. That's all. Thanks!
Try with Ctrl + Shift + V or with middle click with a 3 button mouse
EDIT
What about? Shift + Ins
Source : https://superuser.com/questions/180043/paste-the-windows-clipboard-into-my-putty-session-using-only-the-keyboard
You can insert text from your host’s clipboard by pressing the right mouse button (default setting) or by pressing Shift + Ins. Note that this has the same effect as entering every character manually. So if you are using auto indentation in vim, this will very likely screw up your code.
To fix that, you can do the following:
Before pasting into vim, enable paste mode by entering :set paste.
Press i to enter insert mode. The status bar should say -- INSERT (paste) -- now.
Press the right mouse button to paste in your stuff. The auto indentation of vim should not happen.
If this puts you into the -- (insert) VISUAL -- mode, exit out of it using Esc (putting you into the paste insert mode again), and try pasting it again while holding Shift using your right mouse button.
Press Esc to leave insert mode, and disable paste mode using :set nopaste again.
You can change which mouse button is used to paste in PuTTY in the Window/Selection configuration page.
In Windows Subsystem for Linux it appears that you have to:
i = to enter -- INSERT -- mode
Shift-right-mouse-click = to paste
If you just right-mouse-click (i.e. without shift) then annoyingly all that happens is that the mode changes to -- (insert) VISUAL -- i.e. it doesn't paste anything.
To clarify the other answers, there are a couple ways to do this, depending on if Vim is running with mouse support. Lets assume its via some sort of terminal/Putty:
When not using mouse in remote Vim, right clicking will paste from local clipboard via Putty into remote Vim.
With mouse enabled in remote Vim, Shift + Ins will paste from local clipboard via putty into remote vim.
Ctrl + Shift + v will paste from local clipboard via native/*nixish/xterm into remote vim.
With mouse enabled in remote Vim, middle clicking will paste from remote clipboard into remote Vim.
Copy&Paste between Windows&PuTTY:
To copy from Windows and paste into PuTTY, highlight the text in Windows, press "Ctrl-C," select the PuTTY window, and press the right mouse button to paste. To copy from PuTTy and paste into Windows, highlight the information in PuTTY and press "Ctrl-V" in the Windows application to paste it.
Copy&Past between two vim in separate PuTTY:
highlight the information in the source PuTTY, and then press the right mouse button in the target PuTTY to paste.
Related
I often want to copy text from a :terminal window to a normal text buffer. At the moment I exit the shell session and copy from the history.
There must be a better way to this.
Copy
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.
Entering insert mode will drop you back to your shell.
Paste
To paste from a register into the terminal window you have to be in Terminal-Job ("insert") mode.
Press CTRL-W " followed by the register.
:help Terminal-mode tells us:
When the job is running the contents of the terminal is under control of the
job. That includes the cursor position. Typed keys are sent to the job.
The terminal contents can change at any time. This is called Terminal-Job
mode.
Use CTRL-W N (or 'termkey' N) to switch to Terminal-Normal mode. Now the
contents of the terminal window is under control of Vim, the job output is
suspended. CTRL-\ CTRL-N does the same.
[...]
In Terminal-Normal mode you can move the cursor around with the usual Vim
commands, Visually mark text, yank text, etc. But you cannot change the
contents of the buffer. The commands that would start insert mode, such as
'i' and 'a', return to Terminal-Job mode.
See :h terminal-typing for more useful commands in terminal windows.
1Unfortunately the vim help doesn't tell you that it is a capital N, I kept the original notation
Can use Shift+Insert as a shortcut to paste from the clipboard into a running terminal session. Setup the mapping like
:tmap <S-Insert> <C-W>"+
The will result in pasting from the + register. Alternatively use the * register which sometimes works better in MS Windows.
Set the clipboard setting in your .vimrc to using system clipboard as the Vim's clipboard. Depends on your OS it may differ, assume you are using Mac OS: set clipboard=unnamedplus
Then you can use y command to copy then paste on another app just by Cmd + V, remember to exit the insert mode of the terminal by clicking any where or press Ctrl+\ Ctrl+n
I am trying to paste a string I copied from a webpage in vim. I know that the string is copied in the system clipboard. My vim returns 1 when I run the :echo has('clipboard') command, so I typed :set paste, then positioned the cursor to the desired spot and hit "*p, but this doesn't seem to paste my whole selection. I copied to the clipboard Vader(father figure) but it only pastes Vader. Or is it pasting this because the word behind the cursor is Vader? And finally, what is the easiest way to paste something in vim from the system's clipboard?
I mention that I am using Ubuntu 14.04 (if this has any relevance).
I always use Ctrl+Shift+v in Insert mode, when pasting from system clipboard after doing set paste. Never had any problems doing so.
Otherwise you can use the vim-unimpaired plugin by tim pope and use the yo key mapping set by the plugin to paste. Using yo automatically sets the paste option and after you paste and leave Insert mode, it automatically toggles the set paste option.
Have this line in your .vimrc
set pastetoggle=<F2>
So whenever you press F2 in insert mode you can paste normally with no problems.
For more information refer here.
You only need to set paste if you intend to paste while in insert mode using the middle mouse button or any shortcut your terminal provides.
Now, it is possible that the register you're looking for is quote+. To confirm that just run :registers in order to view the contents of all registers.
I would also advise you to read the following help section :help x11-selection.
I'm currently using the system clipboard in vim as default register in combination with a clipboard manager like Diodon or Klipper (for KDE).
Add this to your vim configuration ~/.vimrc
" Use the system clipboard for yank / delete / paste operations
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
With this configuration vim copy/paste operations (in both directions) behave just like in any other graphical editor (the if has ('unnamedplus') assure that this behaviour is enabled only if vim is compiled with the +clipboard option otherwise behaves as default).
Note: on Windows and MacOS using unnamed or unnamedplus is equivalent.
On Linux are two different entities:
unnamed register is the selection buffer (try to select something with the mouse and then center click or click both sx and dx mouse buttons in another place).
unnamedplus register is actually the system clipboard
I'm using iTerm2. If I'm using vim on local works fine and I can copy some text from my vim session with mouse.
Now I'm connecting to a debian 7, running vim with the same configuration. I select a text and now I can't copy, with contextual menu (right click) the "Copy" function is disable.
Do you have any solution ?
My .vimrc: https://github.com/arnaudlamy/config/blob/master/.vim/.vimrc
Holding Alt when trying to select text helps.
I need to paste some selected block in visual mode to outside of vim. Currently I need to select this block manually from mouse to paste outside of vim.
As selecting texts in visual mode is easier ,it would be efficient to select some text for pasting outside of vim.
You could yank the text into the + (plus) register, that is mapped to the system clipboard. Just select the text in the mode you like and then type "+y.
Disclaimer: Linux
So what I have noticed is you need clipboard support compiled in to your vim. I ended up compiling my own vim, which had the clipboard support. To check run vim --version and look for a +clipboard or a -clipboard, if it's + then yay you have it, if it's - then you need to compile vim yourself or download a version with clipboard support compiled in. Then the answers people have said seem to work. For me "*y copies into the buffer that is pasted by pressing the middle button, and "+y copies into the buffer which is the normal control + c or on the terminal control + shift + c so what I put into my vimrc was
map <C-c> "+y
that way doing control + c me paste it somewhere else by pressing the exact same command
:wq
If you are using GUI-based gvim, simply yank your text into the "clipboard register" by prefixing your yanking command with "+. That is, when you have finished selecting your text in visual mode, press "+y to yank your text then it will be in your system clipboard.
If you are using text-based vim and your vim has clipboard access to your current system, it's just the same as gvim. If your vim has no clipboard access, try to establish the clipboard connection as described in this page:
http://www.quora.com/How-can-you-copy-all-contents-of-a-text-file-opened-in-vim-through-Putty-on-a-Windows-desktop-to-Windows-clipboard
You can bind contents of the visual selection to system primary buffer (* register in vim, usually referred as «mouse» buffer) by using
set clipboard^=autoselect
You have to identify the register that vim is using to get the outside clipboard.
First copy any text outside vim and then inside vim do the command :registers and look for the text you copied, once you have identified the register simply use it every time you need to copy and paste from the outside:
for example:
Im using gvim in Windows7 and the register used by vim to get the external clipboard is
*"
then in vim select the text and do
*"y to copy (yank) and paste outside as usual
and to paste inside vim from outside do *"p
you can also do a map to the register to easy copy/paste
I am running Vim 6.3 through putty and putty connection manager. I have the mouse option set (set mouse = a). I am able to paste things from the (windows) clipboard to vim by but selecting text in vim isn't copying anything to the clipboard. Does anyone know how do I do this?
Note: I can't update Vim to a newer version.
Hold down shift, and then highlight the text you want to copy using the left mouse button. When you release, the highlighted text should be in the Windows clipboard.
You can select some text with the mouse and then type:
"*y to yank the selected text to the clipboard, then you should be able to use the clipboard content in another application.
if "*y is to cumbersome to type, you can put the following in host .vimrc
:noremap y "*y
Ctrl-Insert to copy, Shift-Insert to paste
Do not use mouse=a.
Put the mouse in commandline mode (:set mouse=c).
Then you can just select your text to put it in the system clipboard (as with all other PUTTY/KITTY commands),