Copying all lines to clipboard from VIM in cygwin - bash

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.

Related

Copy from Ubuntu 20.04 Vim and paste to another application

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.

How do I more easily copy and paste all the content in open file on remote server over ssh using tmux and iterm2?

Problem: I'm on a mac running a tmux server. Within my local tmux session, I connect to a remote linux server and open a file with vim. The text I want does not fit in a single pane without having to scroll. I want to grab the text in the file and copy and paste all of it to my local machine's memory.
Current Solution:
My current procedure for copying and pasting is very convoluted:
Zoom on the pane with ctl-b z
Turn off numbering in vim with :set nonumber
If the file or text I want does not fit in entire pane, I hit cmd - until the text is small enough to fit in the entire pane
Select text I need with my mouse while holding down the option key.
Hit cmd-c to copy to my local machine.
Better Solution?
My current solution is tedious and I'm tired of wondering if there is a better way. Anyone got a better solution?
Ideally, I'd love to be able to select the text with vim and have iterm2 somehow detect what has been selected in a pane and run a single keystroke to copy to my local machine. Not sure if that's possible or not.
OK, I went with the solution at github.com/wincent/clipper which works on my mac running macos 11.2.3.
The install instructions seem to be a little dated and are a bit confusing if you don't read them carefully. It took some trial and error to figure out how to get this working with vim on the remote machine:
Install with brew on your mac
Launch clipper as a daemon with brew services start clipper
On the remote machine, add the following line to your vimrc file:
nnoremap <leader>y :call system('nc -q 1 localhost 8377', #0)<CR>
Note: I had to add the -q 1 in there because I found vim would hang otherwise. The -q 1 arguments are not in the official documentation.
In your mac's ~/.ssh/config file:
Host *
RemoteForward 8377 localhost:8377
Make sure your remote server has port 8377 open!
On the remote machine, open a file with vim. Yank some lines. Then hit <leader>y.
Note: It took a while before it finally dawned on me that just <leader>y doesnt' work by itself. It's a two-step vim command process: 1) yank the text with a vim command 2) send the copied text to your mac with <leader>y.
That's it. My life feels so much better now. :)

Using at windows batch file edit files with vim

I found very useful information on stackoverflow on how to batch edit with vim. However I'm having problems when I want to do that for several files. It executes the first command properly and then stops. Here is an example:
vim mtc04.f90 +"1,$s/mtc03/mtc04/g" +"wq"
vim mtc04.flo +"1,$s/mtc03/mtc04/g" +"wq"
The idea is to replace "mtc03" by "mtc04" in a whole bunch of files, but after executing the first command it stops. How can I make it continue. I think this is just a basic question about windows command files rather than a vim question, but I don't know the answer, and could not find it.
vim being a windows version of the Unix vim editor.
You would preferably need to call it, let the batch wait for it to complete, before it starts the next edit.
call vim mtc04.f90 +"1,$s/mtc03/mtc04/g" +"wq"
call vim mtc04.flo +"1,$s/mtc03/mtc04/g" +"wq"
If all the files have the same basename, you can do the following:
vim mtc04.* +"bufdo! %s/mtc03/mtc04/g" +":wqall"

"edit" not a valid command in cmd.exe?

I'm trying to create a .cfg file for bcc32 compiler and I'm following the instructions. I have installed correctly and placed an environment path as instructed but when I type "edit bcc32.cfg" into the command prompt it says that edit isn't a valid command? What am I supposed to do?
You could also create a .bat file, edit.bat, to replace the 16-bit edit program (removed because x64 windows flavors won't run it) which would launch your favorite editor.
#echo off
notepad %1
#echo on
This is what I wound up doing as a simple patch so I could carry on the way I always had for the most part. Just type:
edit myfile.ext
in the command prompt to use it.
Note: notepad is not my favorite editor - this is just an example that will work with stock windows.
Note 2: #echo off and #echo on are shown for clarity. You may also shorten this by omitting the echo statements and simply placing the # before the command to be silenced.
#notepad %1
I just use notepad (since they took out the edit command) from the command window like so:
C:\Borland\BCC55\bin> notepad bcc32.cfg
The file will open in notepad for editing. When you've finished editing the file, save it and you're done.
I have found this works for seeing in-window text of a complete file, on a 64bit machine. Once your path is set in cmd prompt, type the word type... followed by "filename" do you see how I used the quotes around the filename only!
type "filename"
You type it just like this (changing filename for your files name) and you will be able to see the entire file text in the cmd window. Not sure how to edit from here on but maybe someone can figure it out from here and tell me.
Assuming you're using Windows 7 (where edit.exe and edlin.exe have been removed):
Use powershell.exe instead of cmd - thereby edit will be available via command line.
Take a look at: http://en.wikipedia.org/wiki/Windows_PowerShell
simple answer....
if your using an old version of windows (xp e.t.c...) you would be able to use edit
but since your using new version of windows, Microsoft has updated and removed the commands that they think are not relevant e.g.. (msg, edit) depending if its a bit32 bit64 or bit82...

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