So, thanks to Screwtape, I've got an answer for this. Reproduced below:
The original xterm
mouse protocol only supports up to 223 columns and
lines. Later versions of the protocol used UTF-8 encoding, which turned
out to be a terrible idea, and more modern terminals support
a completely different protocol based on the SGR escape sequence that's
much more sane.
tmux
automatically supports the original protocol and the SGR protocol
both ways (to the terminal it's running inside of, and to the
applications running inside it.) but it only requests UTF-8 mode from
the outer terminal if 'mouse-utf8' is enabled in the config file.
You can use the vttest
tool to experiment with different mouse protocols
inside and outside tmux
to get a better idea what's going on.
According to the documentation for Vim's 'ttymouse'
option, it will ask
the terminal for original-xterm-protocol support if $TERM
is a variant
of xterm
, mlterm
or screen
(and tmux
reports itself as screen
, so that's
OK). If the terminal supports the "RV"
termcap feature to determine the
xterm
version number, Vim will use that to automatically upgrade to
'xterm2'
or 'sgr'
mouse protocols... but typically only xterm
advertises
"RV"
support, so tmux
is left out of the automatic upgrade process.
In my ~/.vimrc
I have the following code to enable decent mouse support,
instead of relying on Vim's autodetection:
" Screen/tmux can also handle xterm mousiness, but Vim doesn't
" detect it by default.
if &term == "screen"
set ttymouse=xterm2
endif
if v:version >= 704 && &term =~ "^screen"
" Odds are good that this is a modern tmux, so let's pick the
" best mouse-handling mode.
set ttymouse=sgr
endif
(Of note, the set ttymouse=sgr
is the actual fix, here; I suggest adding it to your .vimrc
as Tim did.)
Best Answer
Check out this vim script, it does what you want.
Also, thanks for the tip, I hadn't thought of this and it sounds like a great idea.
FYI after playing with the linked tip for a while, this is my result:
noremap <silent> <Leader>vs ggzR:<C-u>let @z=&so<CR>:set so=0 noscb<CR>:set columns=160<CR>:bo vs<CR>zRLjzt:setl scb<CR><C-w>p:setl scb<CR>:let &so=@z<CR>
It does what the tip in the link does, with the addition of moving to line 1, setting the width of the double-wide screen to 160 columns, and opening all folds. Starting anywhere but line 1 was causing me problems and folds were making things inconsistent.