What I want in Vim with the mouse (and why I don't think I can have it)
I've recently been working on improving my vim environment, as part
of getting better with it in general, and one of the things I've
been doing has been turning on its 'mouse in
xterm' support. This
led me to a tweet:
I wish vim (in xterm) gave me better control over which mouse actions it did special things for and which ones acted just like xterm.
Since Twitter is not the best place to explain this, time to elaborate.
What I want is for vim to do things with the mouse, but for both
middle mouse pasting and general selecting things to act like plain
xterm. In any context where pasting things generally makes sense
(so far, in insert mode and when I'm telling vim what to search for
?), the middle mouse button should paste the X
selection. If I used vim intensely, I might
be happy with its default behavior of the middle mouse button pasting
in vim's unnamed register; since I don't, I found it infuriating.
As far as mouse-based selection goes, I would like vim to handle
double and triple-clicks more or less like
xterm does and to export the resulting vim visual selection
as the X selection.
(I'm aware that I can use shifted clicks in
xterm to get much of this, but using Shift in
and having to remember to do so is too annoying. I want plain mouse
clicks to do the right thing.)
In reading through vim's help text, it seems that vim can at least
come close to this with the right
.vimrc settings. Unfortunately,
there are two obstacles in practice. The first is that I need a
version of vim compiled with the +xterm_clipboard feature. On
all of the machines I use vim on, the normal
vim program is not
such a version. On some machines a suitable version is available
vimx; on others, it's not currently available at all and I'd
either have to get additional packages installed or compile my own.
But the bigger problem is that this vim behavior requires having
$DISPLAY available, in other words a live connection to my X
server. Unfortunately, I often use vim in situations where I am
sshing in to other machines, and despite improvements in Internet
speed I do not want to have
$DISPLAY set. Among other things, making a
triggers all sorts of undesirable behavior in various other programs
that I use. It is not worth trying to upend my environment this way
in order to get the mouse working right in a mouse-aware vim.
It would be nice to be able to click things to move the cursor to
them and to adjust the relative size of vim windows by grabbing the
status bars, and probably other things I haven't found yet. But
it's not worth making my select and paste life clearly worse, because
I do a lot more select and paste inside vim than any other use of
the mouse. So at least for now, I've stopped setting
anything in my
(And I'm not currently interested in using a fully graphical vim. If I'm going to fire up a program that'll open up its own X window, so far it's going to be either sam or GNU Emacs, both of which I already have carefully configured for this purpose.)
PS: I'd be happy to be wrong about this, but as far as I can see
the need for
$DISPLAY is explicitly confirmed by vim's documentation.
This is unfortunate, as modern versions of xterm (and possibly other
terminal programs) offer access to the X selection through escape
sequences, but it is what it is.
Sidebar: Why I care about having this be universal
I use vim in all sorts of different environments on all sorts of different machines, because it's my sysadmin editor. I want and in fact I need these various different vim environments to behave as much like each other as possible, so that I can develop a single set of vim reflexes that work everywhere (or almost everywhere). If some of my 'vim' environments behave one way (because I've set up a non-default version of vim and configured it) and some behave another way (because I haven't), I will be shooting myself in the foot.
It might work to start using graphical vim (ie, vim in its own window, not just running in an xterm), in the hopes that I would see graphical vim and vim-in-xterm as two sufficiently separate environments. But even that's a gamble and I'm not sure I want to find out how my reflexes react. It's simpler to just give up on smart mouse use in vim for now.