Using a Mouse with Vim
Hint: To make Vim behave exactly as it does in this post’s video, download mouse-vimrc and run Vim with vim -u mouse-vimrc
.
Console Vim works shockingly well with the mouse. Selections can be made, windows resized — all without using gVim or MacVim. I’ve written about training yourself to use hjkl
instead of the arrow keys before, and while I'd encourage people to learn the window management keys, the mouse options are worth trying out.
There are two important options: mouse
and ttymouse
, and both have associated documentation (:help 'mouse'
, :help 'ttymouse'
). The first option enables the mouse, and I usually set this to a
which means the mouse will work in the Normal, Insert, Visual, and Command-line modes.
The other option, ttymouse
, changes what "mouse codes" Vim will recognise. I found xterm2
worked well with iTerm2 in Mac OS, but I was unable to get Lion's standard Terminal to work.
It’s also worth checking out the ttyfast
option as well. It's meant to cause Vim to send more characters when redrawing, but it feels fast either way on my machine.
All together that gives the following:
" Send more characters for redraws
set ttyfast" Enable mouse use in all modes
set mouse=a" Set this to the name of your terminal that supports mouse codes.
" Must be one of: xterm, xterm2, netterm, dec, jsbterm, pterm
set ttymouse=xterm2
You can see me playing around with these settings in this short video: