Possible to use Cmd+c to copy vim selection? - macos

I've been looking for at way to copy from vim to my system clipboard. I've read through the question "How to copy to clipboard in vim" and from that I can see that i'll have to compile Vim with +clipboard.
This is not an option for me, when working on a remote server, so for now, I'll have to switch to the mouse, to make the selection to make my system regard the selection a selection. Simply doing a visual select through Vim does not work.
So my question is this;
Is it possible to make my system see the selection made by Vim (e.g. using viw) as something that can be copied to the clipboard using a cmd-c?
I'm using Mac OS High Sierra, running iTerm 2.

I have a car without wheels, can it drive anyway?
Well, the answer is no, unless you strap some sort of wheels or similar to it.
xclip may be a solution (:'<,'>w !xclip -i) but if you can install stuff, it would be easier to install a proper version of vim.

The idea of using xclip will only work if you're on a local machine.
If you're on a remote server and use xclip, it will copy the text to the remote clipboard, making it unavailable locally.
There are ways around this, and you can adapt them from this post, which can be summed up in either:
Use and ANSI escape sequence
OR
Setup communication with the server and an SSH tunnel (yes, not complicated but quite involved)
The first way is actually quite easy, because you just need to enable access to the clipboard from the terminal in the general preferences of iTerm, and then if you do
printf "\033]52;c;$(printf "%s" "YOUR_CLIPBOARD" | base64)\a"
then the text YOUR_CLIPBOARD will be copied in your local clipboard, even if you're on a remote server.
All you have to do is put that printf in a shell script that take what you want as input and map whatever shortcut you want to running the script with the selection as a parameter.

Related

How to get tabs in unix session on putty

I have used an script in past that enabled me to connect me to multiple unix machines, much like using a tab. Its just that I forgot the name of the script. Anyone know about it?
I suspect you're referring to GNU screen, which is a terminal multiplexer that allows you to have multiple virtual terminal windows in a single normal terminal window (ala PuTTY). I'd suggest tmux as a better alternative, but they're essentially the same. There are other solutions that will allow you to do tabs in the terminal client, but that depends on your OS (I'm assuming you're on Windows), and you'd have to initiate each connection individually. screen/tmux is the way to go most of the time.

Is there any way to prevent ncurses based programs from running?

Hey there, I'm building a remote shell server that interfaces between a text-only client and a virtual shell.
It works perfectly when using regular shell commands, but the first thing that people try after that is vim, which promptly drives my server crazy and can't even be closed remotely.
Is there any way to detect ncurses based programs and prevent them from running in my special shell?
(the server is ruby, but any system command will do)
You can declare the capabilities your shell has, by setting the TERM environment variable to the correct value. For instance, if your shell has the same capabilities as the vt100 terminal, export TERM to the correct value, and programs like vim will respect that.
To run vim in vt100-mode, try:
TERM=vt100 vim
You could also try:
export TERM=dumb
The trick is to find a terminal that corresponds to the capabilities of what you are creating. There is a lot to choose from. On my system (Arch Linux) this gives me a long list of choices:
find /usr/share/terminfo
You might be able to find a terminal specification that corresponds to what your program can handle.
Alternatively, you may want to consider implementing terminal emulation for ansi or vt100:
http://en.wikipedia.org/wiki/ANSI_escape_code
http://www.termsys.demon.co.uk/vtansi.htm
Best of luck!

Best way to make a script to SSH?

My university has quite a lot files (like past papers etc) which I need to be on the uni network to access them. I ssh, using port forwarding, into the network and set my browser (Firefox) to go through that port. I know it would be quite easy to write something in most languages that would enter the command into a terminal, but which language/method could I use to make this happen? I expect some sort of scripting language could but I really know nothing about them, but I'd be willing to learn one just to have a little fun with this.
I'm using a cygwin terminal on Windows 7, if that will make a difference.
To neaten up my question: Which language would be best to acheive the above effect? Not necessarily the best, just possible and relatively simple to learn. I used the word best so I suppose I'll put a subjective tag.
EDIT:
Just in case anyway wants to do this precise thing, I'll show my solution. I ended up using a batch file because a few things made the bash more difficult. Anyway, in order to SSH into the network and open a new firefox window with the proxy changed, I just have to open this batch file and enter my password.
cd C:/cygwin/bin
ssh -fND 9001 username#your.website.here
cd "C:/Program Files/Mozilla Firefox"
firefox -no-remote -P SSH_profile
Save as .bat
In order for this to work you need to set up a profile with name SSH_profile (or whatever) and set the connection settings to go through port 9001. The script will open use the ssh command in /cygwin/bin and enter in the information. You enter your password and then it goes to your firefox directory, uses those arguments which opens a separate profile with the connection settings changed (means you can view unaccessible files in one window and anything else you don't want to be on your uni network in another. Just close the windows when you are done.
Quite a specific case but I thought I'd share my answer in the hope of helping someone, some day.
Since you are using cygwin, write a bash shell script.. If you don't want to rely on bash, powershell would be what you want, although you could probably get it working using a batch file.
This is exactly the kind of thing shell scripting is for.
Edit
You can change the firefox settings on the command line by passing the -override flag. This will let you have special settings for the invoked process.

How do I open files over FTP with Emacs 22.2.1 on Windows?

AngeFtp? EFS?
Is there a better option?
Is the preferred option built-in?
If so, how do I turn it on?
If not, where do I download it?
I tried with AngeFtp, just by doing find-file using a filespec like
/name#server:/directory
and it prompts me for a password, then does the login to the FTP server and gets the contents - it takes a while - but when it finishes, I don't get or see a dired buffer. I just get a blank buffer with a weird name.
Tramp is the modern replacement for ange-ftp.
The short version is, you specify a file like "/myusername#host:path/to/file". Works like a charm.
View the linked documentation for installation instructions, though it might already be installed if you have a fairly new installation of emacs. Also, there are several questions related to tramp and remote development with emacs on SO
I just use C-x C-f or C-x C-d, with the remote-file format /host:/path/to/my/dir/. And I customize tramp-default-method to "ftp". Works like a charm. When it opens the connection for the first time (only), it prompts for the password.

Another shell open when at server?

How can I have another Terminal open when I am at my server by ssh?
I do not want to type my password twice to get another terminal for my server.
Perhaps, Bash has buffers similarly as Vim.
Check out GNU screen. It's kind of arcane and awkward to use, but does what you're looking for, and it's probably also installed on your server.
You can also forward X11 and run multiple xterm instances, but that's a pain.
Your best bet, though, is your proverbial "type my password every time" solution: you should set up SSH keys so you don't need to type your password every time and then just use multiple connections in Terminal tabs.
You can use something like GNU Screen.
The Bash shell has a feature called Job Control that allows you to run and manage multiple processes. You can read about it here: http://commandlinemac.blogspot.com/2008/12/bash-job-control-fg-bg-jobs-and-ctrl-z.html
GNU Screen
BTW. If you don't like typing passwords, try PK auth.
How it's done with PuTTy.
It's possible to use screen to open other terminals without needing to authenticate again.
Screen can also detach so that you can leave terminal open after logging out and re-attach them later. I use this on my home server for keeping rtorrent open.

Resources