Copy from Ubuntu 20.04 Vim and paste to another application - windows

Problem definition
My goal is copy code from vim and paste to browser.
It doesn't work as expected "+y and "*y command.
I have tried each two commands and tried ctrl + v to another application, but nothing happened.
I don't know what's problem.
What I tried
I've already seen these.
How to make vim paste from (and copy to) system's clipboard?
How can I copy text to the system clipboard from Vim?
Not only these but also lots of another Q&As.
I have tried these but still doesn't work.
My environment
I'm using Windows 10.
And on windows, I installed Ubuntu 20.04 and using VIM.
Result of vim --version | grep 'clip' is here.
+clipboard
As you see, clipboard and xterm_clipboard option is enabled.
And as said another Q&A of links, I append set clipboard=unnamedplus into my vimrc file.
But the result did not change.

As I understand you want to copy from vim in WSL to Windows. Unfortunately WSL and Windows have different clipboards, but this is solvable. For example in order to copy file contents from WSL to Windows clipboard, you need to pipe file contents to clip.exe:
cat myfile | clip.exe
So in vim we can:
yank your selection
Drop to command line and type :! echo
Paste the selection with Ctrl + r "
Continue typing in the command line: | clip.exe
hit Enter and profit!
Probably it would be useful to write some autocmd for this in vimrc.

Related

Can't figure out how to copy between VIM terminals on OS X

I know I need to copy into the " or * registers or something like that
Let's say I have one c program in one terminal running vim and another program in another terminal...
How do I copy a line between them?
Visually select the line you want to copy with V.
Hit "*y to yank the line into the * (clipboard) register.
Open the other terminal and vim inside it.
Hit "*p to paste or press i and then paste the info in there (like you would normally copy paste).
If this does not work then you may need to run vim --version and see if your copy of vim is compiled with a +clipboard. If it says -clipboard then you will need to install a version of vim that was compiled with clipboard. Results may vary when ssh-ing into a server.

Cannot paste into Intellij Idea from Vim

After yanking a text from Vim I cannot paste the clipboard content into Idea's editor window. I can, however, paste it in every other window (browser, terminal etc.).
The text becomes "pastable" (strangely) after I run command in a terminal:
xclip -sel c -o | xclip -sel c
or paste a line somewhere and copy it manually (Ctrl-C or mouse).
I have set options
set clipboard+=unnamed, unnamedplus
in both Idea (ideavim) and vim.
My system is Fedora 25. This problem manifested itself after I changed distribution, so maybe Wayland has something to do with it.
Just want to share my situation. I've installed both xclip and xsel for neovim. It turns out that the contents piped to xsel was not recognized by intellij.
I uninstalled xsel and it works fine.

Copying all lines to clipboard from VIM in cygwin

Has anyone found a good way to copy all lines from VIM in cygwin?
I've tried yanking the lines but it doesn't go to windows clipboard. Any ideas?
This seems to be a solution but it is a lot of work for copy/paste:
http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim
UPDATE:
this works:
echo 'put this on my windows clipboard' > /dev/clipboard
BUT doesn't work for me because I want to copy to clipboard while SSH'd into another machine. So echo'ing/cat'ing to /dev/clipboard will put it on the other machine's clipboard, not mine
There may be better ways, but here's how I do it:
Use visual mode to highlight lines to be copied to clipboard (From command mode, v, then navigate normally to highlight).
"+y
to copy to clipboard.
Since the question asks how to copy everything:
ggVG"+y
This is maybe not as easy as you wanted it to be, but here is how I usually do it myself:
:w
:!cat %
This will display your file, and you can copy it from there.

Read only for open directories in vim

Then I open vim from terminal and open an directory like vim ., my starts in Read Only Mode.
I cant figure out why this happen and how I can change it.
If I start MacVim everything is fine. But then I start vim from the terminal and open a directory this screen comes. I can navigate one dir up and back again, and I have write access.
EDIT
I installed all my vim settings on Ubuntu 15.04. Now I can use
Does anybody know how to change this behaviour of vim?
Now I can use netw with the command vim . like I always used.
As you can see, there is no RO (read only) mark. How can
I have this in Mac on iTerm too?
What you see is exactly what you are supposed to see when doing $ vim .: the built-in netrw plugin displays a listing of the current directory that you can use to navigate your project.
If you don't want that listing, don't ask for it:
$ vim
or:
$ vim file
ctrl-p is not mapped by netrw; on my system, its set up by the yankring plugin. If vim is doing something other than going up one line, then you have a plugin involved. Try using :map to see what its mapped to; then do a search for that in your plugins directory.
The netrw way of opening a file in the same window is to use the <enter> key, although the g:netrw_browse_split variable may be used to change that default behavior.
Netrw opens in read-only mode, and that's not going to change. The file being opened should not be in read-only mode, however, if that's what you meant. If you're having a problem of that sort, please update your netrw; the most up-to-date version is at http://www.drchip.org/astronaut/vim/index.html#NETRW .
After I installed macvim 7.4 Every thing works!

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>
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)
You can copy from/to the clipboard in both vim and bash using ctrl + ins for copy, and shift + ins for paste.

Resources