I'm a very happy user of MacVim, which very nicely integrates vim into a native Mac app. But occasionally I need to edit code via a terminal, which means dropping back to plain old vim. Recently I found myself working on a project that was distributed on a self-contained virtual machine, and after several days of mucking around with mounting the VM's filesystem via
sshfs and suffering continued networking drop-outs, I decided to bite the bullet and move to working entirely within the terminal.
Mostly, the transition was fairly simple. I was able to copy over my
.vimrc and the contents of the
.vim directory to my home directory on the VM, and almost everything 'just worked'. There were a few exceptions.
The first thing that I missed was the mouse. Although like any good vim user I do stay mainly on the keyboard, it's nice to have the mouse available occasionally as an alternative for things like rapid scrolling with the wheel, tab/window switching, and text selection. I initially thought I would just have to do without, but it turns out that it is quite possible to have the mouse working within the terminal.
The main issue is that although there is a well-defined way for an xterm terminal to send mouse events, the OSX Terminal app doesn't support it. However, there is a nice easy hack that does work: MouseTerm. This is a SIMBL plugin which patches the terminal so it sends mouse events. I already had SIMBL installed, as I use Ciarán Walsh's indispensible TerminalColors to make the terminal colours sensible, so it was just a matter of clicking the MouseTerm .dmg to get it working. Then I just added
set mouse=a to my .vimrc, and hey presto: mouse in terminal vim.
Secondly, tabs. I use tabs all the time in vim. MacVim overrides vim's built-in tabs with proper native ones, so that you can open them in the standard way - eg opening documents in new tabs via
:tabe - but then switch between them with the standard OSX shortcut keys,
cmd-]. In the terminal, the first of these continues to work, but since the tabs are now vim's own ones, switching needs to be done by the vim shortcuts of
gT. Not too much to learn - I might try and force myself to use those within MacVim, for the sake of consistency.
Thirdly, extensions. As I said above, most of these just worked by copying over my
.vim directory. But one of the ones I use most of all - the excellent Command-T file navigator - did not. This was because the version of vim installed on Ubuntu by default via
apt-get install vim does not include Ruby support, even though it does include most of the other options. Removing that and installing the
vim-nox package instead rectified that.
The final issue is cursors. MacVim nicely distinguishes between insert and normal mode by switching between bar and block cursors. In the terminal, this doesn't happen. It appears to be possible to send custom escape sequences when switching modes: the
termcap-cursor-shape help topic explains how. But I couldn't get this to work even for the examples in that topic, which switch colour rather than shape; I don't even know how to begin finding the right escape codes to change the cursor shape. In any case, I suspect something in the interface between Terminal.app and the Ubuntu bash shell is preventing colour codes from working - for example,
printf "\e[0 32 m" works in the OSX shell to change the text colour to green, but the same command fails to work when I'm ssh-ed in to the VM. Any hints would be gratefully received.