I use iTerm2 in place of the default Terminal on MacOS or OSX. I was working on a project that has some Debian Stretch VM’s in Google Cloud, so I was logged into those VM’s via SSH using iTerm2. On previous operating systems I would SSH into using iTerm2 I had been able to simply highlight text in the the terminal, which would copy it and I could then paste that text into a text file for either modification or to backup the file from the Linux server itself. It appears that something changed in a recent version of Debian that now puts things in a weird mode when attempting to copy text in that way from a SSH window. Below I list steps for enabling the ability to copy/paste text from a iTerm2 SSH connection on Debian Stretch.
Copy/Paste Text In vim From iTerm2 SSH Connection
The change that does not allow copying text in the same manner as before in iTerm2 appears to be a default configuration change in iTerm, but can be modified to the previous functionality using the steps below.
Open iTerm2 Window On MacOS
If you have iTerm2 on the MacOS dock simply double click the icon shown in the image below.
If you do not have the iTerm icon located on the MacOS doc then open a Finder window, navigate to applications and double click iTerm.app.
Create or Open .vimrc vim Settings File
The .vimrc file containts Vim runtime configuration settings on your MacOS computer. To open the file for editing using Vi use the command displayed below.
- acomputerhere:~ alex$ vi ~/.vimrc
The above command either opens the existing Vim runtime configuration file or modifies the existing Vim configuration file for a specific user, which would be alex in the example above.
Set Vim Clipboard Setting In .vimrc
Now add the following configuration line to the open .vimrc file, which sets clipboard+ to unnamed.
- set clipboard+=unnamed
To save and quit the file type “:wq!”.
You should now be able to copy text in the manner that you previously could using iTerm on MacOS.
Click here for more information about iTerm2 the MacOS Terminal replacement or click here for more iTerm2 articles from Question Defense.