I use VSCode on macOS, I ssh into Linux remote station and here I run tmux (inside VSCode integrated terminal). However, I am not able to copy any text from tmux into system clipboard when used like this. I am not even able to select the text using mouse - when I select any the selection highlight disappears immediately.
The copying to system clipboard works if:
I run tmux inside separate window of iTerm2
I run normal zshell inside VSC integrated terminal
How to copy text from tmux inside VSC integrated terminal?
That is because vscode terminal does not support osc52. We gotta wait for this issue to be resolved https://github.com/xtermjs/xterm.js/issues/3260
OSC 52 (OSC stands for Operating System Command, a category of ANSI escape sequences which instruct the terminal emulator to perform certain actions) is a terminal sequence used to copy printed text into clipboard, without which copying from remote machine will not send the result to your local clipboard. Applications like tmux support it (actually, tmux is kinda forwarding it), iterm2 support it but not vscode
Solved using the mouse while holding Alt (Option) key. This way I can copy text from Tmux inside VSCode.
Related
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. :)
I am on Windows 7 and I have Git Bash at my disposal after installing Git for Windows.
I found mouse inconvenient to select-copy-paste in terminal window. What is the shortcut for text selection (like Shift+←, Shift+→ in Notepad editor)?
I have seen many irrelevant verbose replies to this question, but all, what I am looking for is just an appropriate shortcut (like Ctrl+Insert for Copy and Shift+Insert for Paste).
It is best to install a CMD enhancer like ConEmu.
From there, you can type "bash", and you will see in that Git bash session, that simple CTRL+C, Ctrl+V are enough for copy/paste.
And for selecting the text (in a ConEmu session), Shift+←, Shift+→ works too. For W7 or W10.
The issue I am having is when I open a file via emacs it will open another window in the emacs text editor, but lock out the terminal. What I mean by lock out is that the terminal seems to be linked to the window of emacs that had opened up. When I first downloaded the software I did not have this issue and was able to open multiple emacs windows at once but now I have to close out of the current emacs window to open another. Any suggestions on fixing this?
It sounds like you want to have the file pop up in a window when you open it, rather than fill the whole terminal.
If that's the case, you should
install a graphical version of Emacs from http://emacsformacosx.com/
put alias emacs=/Applications/Emacs.app/Contents/MacOS/Emacs in you ~/.bashrc
open files with emacs file.txt &. The file will open in a separate window and you can keep using your terminal
Can anyone help me with this:
I'm trying to figure out how to copy and paste text between 2 different instances of vim on different terminals (using iterm2 or mac terminal). I can do it using the mouse if I do ":set mouse=a" but I'd like to be able to do it using the keyboard.
I've googled around and it says you can use the "* or "+ registers to copy/paste to/from the system clipboard, but when I type * or + in vim, the mac makes one of those sounds it makes when you can't do something. I've also done ":set clipboard=unnamed" but that hasn't worked either.
I'm using Mac OSX 10.7 (Lion) and iTerm2 or Mac terminal.
Thanks for the help
Could you add the output of :version?
I can yank with yy or y in one Vim instance running in Terminal.app window A and put with p or P in another Vim instance running in Terminal.app window B with this line in my ~/.vimrc:
set clipboard+=unnamed
without using specific clipboard registers (* or +).
And why do you have two Vim instances running in different terminals? SSH/local? If one is in an SSH session yanking/putting won't work because the two machines (local/remote) don't share the same clipboard(s).
EDIT
I suspected that Vim wasn't compiled with the right flag(s). Apparently that's the case.
Since you are using Mac OS X's default Vim my opinion is that you shouldn't need to re-compile it or even compile anything as it often leads to more problem's than it's worth.
Instead, download the latest MacVim build and use the (CLI) Vim executable within MacVim's bundle: it has all the same functionalities as MacVim (within the constraints of the CLI, of course).
Add this line to your ~/.bashrc or ~/.profile or wherever you are used to put aliases and custom bash functions:
alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'
If you want to copy an entire file into your target file.
Open your target file in vim.
Put your cursor where you want it and type the following:
:r /path_to_file/file.ext
This will copy an entire file to where your cursor is...
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.