Saturday, November 19, 2011

Mouse support for scrolling, vi/vim, and more!

Goofing around on the internet today just got real. I was reading about ncurses and noticed that the API supports mouse events. So wait, if terminals can support mouse events, then why doesn't vim in work like gVim and support mouse scrolling, clicking, and selection? It can, and it's AMAZING!

Someone wrote a SIMBL plugin called MouseTerm that passes through all mouse events to the terminal. After that, all you have to do is enable mouse support in vim, and Boom goes the Dynamite!

1. Install SIMBL
2. Install MouseTerm
3. Edit your .vimrc:

" mouse support
if has("mouse")
    set mouse=a
    set ttymouse=xterm2
4. That's it! Now you can use the mouse for clicking, selection, and scrolling!

One thing I did notice is that you can no longer copy text to the Mac clipboard from Vim in this mode. It's easy to toggle mouse event passing with Cmd-Shift-M (or menu item Shell > Send Mouse Events).

I used the ttymouse=xterm2 since it is the one recommended for use with gnu screen. ttymouse=xterm didn't behave properly for me when vim was used inside of screen.

Thanks to Ayaz for this article on "Using mouse inside Vim on" which got me pointed in the right direction.


  1. TLDR; hold down option key to copy and paste

    Date: 2009-11-03 15:41:57 PST
    Sender: snorkel70

    To be clear -- if you disable mouse usage in vim, then you don't need the
    option key to select text in iTerm with vim running to copy it to the Mac
    clipboard. If you want to use your mouse in vim then you have to remember
    to use the option key to select text.