Copying stuff from vim running in putty - vim

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),

Related

How to copy(External Sources) and paste on Vim [duplicate]

Unlike other editors, vim stores copied text in its own clipboard. So, it's very hard for me to copy some text from a webpage and paste it into the current working file. It so happens I have to either open gedit or type it manually.
Can I make vim paste from and to the system's clipboard?
Be aware that copying/pasting from the system clipboard will not work if :echo has('clipboard') returns 0. In this case, vim is not compiled with the +clipboard feature and you'll have to install a different version or recompile it. Some linux distros supply a minimal vim installation by default, but if you install the vim-gtk or vim-gtk3 package you can get the extra features nonetheless.
The "* and "+ registers are for the system's clipboard (:help registers). Depending on your system, they may do different things. For instance, on systems that don't use X11 like OSX or Windows, the "* register is used to read and write to the system clipboard. On X11 systems both registers can be used. See :help x11-selection for more details, but basically the "* is analogous to X11's _PRIMARY_ selection (which usually copies things you select with the mouse and pastes with the middle mouse button) and "+ is analogous to X11's _CLIPBOARD_ selection (which is the clipboard proper).
If all that went over your head, try using "*yy or "+yy to copy a line to your system's clipboard. Assuming you have the appropriate compile options, one or the other should work.
You might like to remap this to something more convenient for you. For example, you could put vnoremap <C-c> "*y in your ~/.vimrc so that you can visually select and press Ctrl+c to yank to your system's clipboard.
You also may want to have a look at the 'clipboard' option described in :help cb. In this case you can :set clipboard=unnamed or :set clipboard=unnamedplus to make all yanking/deleting operations automatically copy to the system clipboard. This could be an inconvenience in some cases where you are storing something else in the clipboard as it will override it.
To paste you can use "+p or "*p (again, depending on your system and/or desired selection) or you can map these to something else. I type them explicitly, but I often find myself in insert mode. If you're in insert mode you can still paste them with proper indentation by using <C-r><C-p>* or <C-r><C-p>+. See :help i_CTRL-R_CTRL-P.
It's also worth mentioning vim's paste option (:help paste). This puts vim into a special "paste mode" that disables several other options, allowing you to easily paste into vim using your terminal emulator's or multiplexer's familiar paste shortcut. (Simply type :set paste to enable it, paste your content and then type :set nopaste to disable it.) Alternatively, you can use the pastetoggle option to set a keycode that toggles the mode (:help pastetoggle).
I recommend using registers instead of these options, but if they are still too scary, this can be a convenient workaround while you're perfecting your vim chops.
See :help clipboard for more detailed information.
You can paste into vim by gnome-terminal's shortcut for paste.
Place the file in insert mode and use
Ctrl+Shift+v.
Remember beforehand to
:set paste
to avoid messing with the indentation.
I believe that this question deserves a more objective and pictorial answer:
Entering Paste Mode
ESC
:set paste
press i
SHIFT + Insert (with a text copied on your clipboard)
Leaving Paste Mode
ESC
:set nopaste
press i
You pasted the text and you're able to type again.
For my that configuration works for copying and pasting
" copy and paste
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa
Linux
On my Linux system, the + and * registers map to an X11 selection, which can be pasted with the middle mouse button. When :set clipboard=unnamed and :set clipboard=unnamedplus are used, then the registers map to the clipboard, and can be pasted with CTRL-V.
The specifics seem to be somewhat configuration and system dependent, so your mileage will definitely vary. It should definitely get you pointed in the right direction, though.
See Also
http://vim.wikia.com/wiki/Accessing_the_system_clipboard
This would be the lines you need in your vimrc for this purpose:
set clipboard+=unnamed " use the clipboards of vim and win
set paste " Paste from a windows or from vim
set go+=a " Visual selection automatically copied to the clipboard
clipboard
There is a special register for storing this selection, it is the "*
register. Nothing is put in here unless the information about what text is
selected is about to change (e.g. with a left mouse click somewhere), or when
another application wants to paste the selected text. Then the text is put
in the "* register. For example, to cut a line and make it the current
selection/put it on the CLIPBOARD:
"*dd
Similarly, when you want to paste a selection from another application, e.g.,
by clicking the middle mouse button, the selection is put in the "* register
first, and then 'put' like any other register. For example, to put the
selection (contents of the CLIPBOARD):
"*p
registers E354
> There are nine types of registers:
> 1. The unnamed register ""
> 2. 10 numbered registers "0 to "9
> 3. The small delete register "-
> 4. 26 named registers "a to "z or "A to "Z
> 5. four read-only registers ":, "., "% and "#
> 6. the expression register "=
> 7. The selection and drop registers "*, "+ and "~
> 8. The black hole register "_
> 9. Last search pattern register "/
Paste from clipboard
1. Clipboard: Copy
2. Vim insertmode, middle mouse key
Check for X11-clipboard support in terminal
When you like to run Vim in a terminal you need to look for a version of Vim that was compiled with clipboard support.
Check for X11-clipboard support, from the console, type:
% vim --version
If you see "+xterm_clipboard", you are good to go.
http://vim.wikia.com/wiki/Accessing_the_system_clipboard
The X server maintains three selections, called:
PRIMARY, SECONDARY and CLIPBOARD
The PRIMARY selection is conventionally used to implement copying and
pasting via the middle mouse button. The SECONDARY and CLIPBOARD
selections are less frequently used by application programs.
http://linux.die.net/man/1/xsel
Copy To OS Clipboard
Select text in visual mode, press "*y
Paste From OS Clipboard
Press "*p
Didn't have +clipboard so I came up with this alternative solution using xsel:
Add to your ~/.vimrc:
vnoremap <C-C> :w !xsel -b<CR><CR>
Shift + Right Click -> Paste
did the trick for me
I tried the suggestions above and none of them worked in my environment. (Windows PuTTY clone over ssh)
Some additional googling turned up:
https://unix.stackexchange.com/questions/110684/copy-paste-into-sshd-vim-from-local-windows-clipboard
One of the comments suggested using SHIFT+INSERT which did the trick for pasting from my desktop's clipboard into Vim's buffer. Ctrl-C was already working to copy to the desktop's clipboard from Vim.
The simplest solution to this, that also works between different Linux machines through ssh is:
Check whether vim supports X-11 clipboard: vim --version | grep clipboard. If it reports back -clipboard and -xterm_clipboard you should install either vim-gtk or vim-gnome (gvim on arch linux)
Add the following lines to your .vimrc:
set clipboard=unnamedplus
set paste
If you login on a different machine via ssh, use the option -Y: ssh -Y machine
Now copying and pasting should work exactly as expected on a single, and across different machines by only using y for yank and p for paste. NB modify .vimrc on all machines where you want to use this feature.
What simply worked for me in Linux (Ubuntu 20.04)
Copying to system clipboard:
Select what you want to copy in Visual mode.
Type "+y
Press Enter
Paste something form system's clipboard:
Move to the place where you want to paste the copied text in vim.
Just type
"+P to paste before cursor OR
"+p to paste after cursor.
To know more how this works: Copy and Paste to/from Vim from/to Other Programs!
A quick note for people whose Vim installation does not support the * and + registers. It is not necessary to download a new Vim installation to paste from the clipboard. Here is an alternative method:
Install parcellite (a clipboard manager with a low memory footprint);
In your .vimrc file, add the following:
command Clip r !parcellite -c
Restart vim.
Now when you type in :Clip as an ex command, the contents of the clipboard will be pasted in at the cursor. You can also map the new command to a function key so as to be able to do this with one keystroke.
These key combinations work on any OS.
Select target Text using the mouse, and refer to the key sequences to copy, cut, and paste.
copy: Ctrl + Insert
paste: Shift + Insert
cut: Shift + Del
paste: Shift + Insert
This works for me: Ctrl+Shift+V
If you are using a mouse first do
:set paste
Then right click mouse and the contents in buffer will be pasted
I ran into this issue on a mid-2017 Macbook Pro running vim within iTerm2 as my primary development environment.
As other answers have suggested, I ran vim --version and noticed that it returns -clipboard, which means that the version of vim that shipped with my machine hasn't been compiled with the clipboard option.
The homebrew package for vim appears to compile with the clipboard option, so the fix for me was to:
Run brew install vim
Add set clipboard+=unnamed to my ~/.vimrc file
Close and reopen iTerm2
Following on from Conner's answer, which was great, but C-R C-p + and C-R C-p * in insert mode is a bit inconvenient. Ditto "*p and "+p from command mode.
a VIM guru suggested the following to map C-v to what C-r C-p + does.
You could have :inoremap <C-v> <C-o>"+p for insert mode only
if you really wanted to override blockwise visual mode (not recommended by him as visual
mode is good) you could have map <C-v> "+p
With Vim 8+ on Linux or Mac, you can now simply use the OS' native paste (ctrl+shift+V on Linux, cmd+V on Mac). Do not press i for Insert Mode.
It will paste the contents of your OS clipboard, preserving the spaces and tabs without adding autoindenting. It's equivalent to the old :set paste, i, ctrl+shift+V, esc, :set nopaste method.
You don't even need the +clipboard or +xterm_clipboard vim features installed anymore. This feature is called "bracketed paste". For more details, see Turning off auto indent when pasting text into vim
If you are using vim in MAC OSX, unfortunately it comes with older verion, and not complied with clipboard options. Luckily, homebrew can easily solve this problem.
install vim:
brew install vim --with-lua --with-override-system-vim
install gui verion of vim:
brew install macvim --with-lua --with-override-system-vim
restart the terminal to take effect.
append the following line to ~/.vimrc
set clipboard=unnamed
now you can copy the line in vim with yy and paste it system-wide.
If you have it, try removing this from your vimrc:
set mouse=a
It messes with the paste functionality.
On top of the setting :set clipboard=unnamed, you should use mvim -v which you can get with brew install macvim if you're using vim on Terminal.app on Mac OS X 10.9. Default vim does not support clipboard option.
Based on #lis2 answer, I use a simpler configuration that will not force Insert mode at the end:
" Copy and paste
if has('clipboard') && !has('gui_running')
vnoremap <C-c> "+y
vnoremap <C-x> "+d
vnoremap <C-v> "+p
inoremap <C-v> <C-r><C-o>+
endif
Mind that all these override default Vim mappings:
v_CTRL-C: stop Visual mode
v_CTRL-X: subtract [count] from number
v_CTRL-V: blockwise Visual mode
i_CTRL-V: insert next non-digit literally, which is also mapped to i_CTRL-Q
As an alternative, one can use keys inspired in the "yank", "delete" and "put" Vim verbs: <C-y>, <C-d> and <C-p> respectively. These would only override one default mapping:
i_CTRL-P: backwards search keyword for completion
The other solutions are good if you want to change your vimrc, etc... However I wanted an simple way to copy from vim to my system keyboard. This is what I came up with.
Select the text you want to copy with visual mode v
Press : (it will automatically expand to show :'<,'>)
Type y * or y + (depending on your system) to yank the selected text to the system clipboard
Since vim 8 right click enables visual mode by default. This prevents the "normal" copy & paste (call it a "defect by design" https://github.com/vim/vim/issues/1326).
Fix it by doing:
echo "set mouse-=a" >> ~/.vimrc .
Exit and restart vim.
It may also be worth mentioning, on OSX using Vim, you can select text with the mouse, Cmd-C to copy to OSX system clipboard, and the copied text will be available in the clipboard outside of Vim.
In other words, OSX treats it like it were a regular window, and this is where the much-maligned Apple "Command" button comes in handy.
B-30
There are two simple ways to do this. Make your file in insert mode and
1) press the middle button (the scroll wheel) in your mouse, or
2) Ctrl + Shift + V
What you really need is EasyClip. It will do just that and so much more...
After entering the vim window, press I to enter into insert mode. Then move your cursor to the desire location and press Ctrl + Insert button simultaneously to paste from the clipboard.

Pasting from clipboard in vim

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

VIM iTerm SSH: Cant' copy paste

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.

how to paste to vim when using putty

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.

selecting in visual mode to paste outside vim window

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

Resources