Recently I bought myself a new “ultra-wide” monitor - LG 35WN75C. Quite nice if you ask me. One of its greatest feature is that I can open 5-6 vertical splits of code (I use vim btw) without sacrificing on readability. Soon, I’ve realized that my mouse usage is increasing a lot. Apparently, scrolling through code and selecting things, when out of the-zone™, is far more comfortable with the mouse. How did I find that, you ask?

Clicking on code in the fifth split left to write, actually got registered as a click in the third one. Started to experiment and realized that it registered properly on the 222nd column, but any other column after that got also registered there. Weird. Something happens on column 223?

This is what my vim configuration looked like, when it comes to mouse support:

" Mouse support
set mouse=a
if !has('nvim')
    set ttymouse=xterm2
endif

No idea how did I ever got to that ttymouse=xterm2. Probably copied it from somebody else’s vimfiles. Anyways, apparently mouse support gets activated with set mouse=a. Let’s go into mouse’s help and look for that magical number 223. Open vim, call :help mouse and search for 223.

… and voilà! First result is precisely about that xterm2 value of ttymouse:

     xterm        xterm-like mouse handling.  The mouse generates
                  "<Esc>[Mscr", where "scr" is three bytes:
                          "s"  = button state
                          "c"  = column plus 33
                          "r"  = row plus 33
                  This only works up to 223 columns!  See "dec",
                  "urxvt", and "sgr" for solutions.

So, I get to choose between dec, urxvt and sgr. After a bit of digging, it looks like sgr is the most modern one, supported since 7.3.632. Here’s the patch if you’re into this: http://ftp.vim.org/pub/vim/patches/7.3/7.3.632

So, this is how my “mouse setup” looks like now:

" Mouse support
set mouse=a
if !has('nvim')
    if has("mouse_sgr")
        set ttymouse=sgr
    else
        set ttymouse=xterm2
    endif
endif

The mouse support is now working great well enough, considering we’re talking about a terminal application here.

Y tho?

Why am I telling you all this? It’s a clear example of how one can debug and fix an issue in vim simply by browsing :help. Not to mention that I had two different ways to arrive at the same help page. Notice that if !has('nvim') there? I didn’t even bother to check if the same reproduces in neovim (spoiler alert: it does not). Instead of going through trial and error for that magical number 223, I could’ve just tried in neovim and then go directly into reading :help ttymouse.

One can learn a lot about vim, simply by wandering in there. Apparently having a good documentation helps your users. Modern software tend to overlook that. I tend to overlook it into the software I write and maintain. The new way is writing tutorials and endless README.md pages in the project’s root. We might want to reconsider this.