Friday, September 18, 2009

Mouse Tips

This has been mentioned on the blog in the past, but readers email me about it often enough that it deserves a formal tip. You can use the mouse to resize windows in Vim if you set your mouse as follows.

:set mouse=a

This will even work over a remote ssh session if you also set your term appropriately.

:set term=[the appropriate setting]

Options for term settings are as follows:

in the GUI: "builtin_gui"
on Amiga: "amiga"
on BeOS: "beos-ansi"
on Mac: "mac-ansi"
on MiNT: "vt52"
on MS-DOS: "pcterm"
on OS/2: "os2ansi"
on Unix: "ansi"
on VMS: "ansi"
on Win 32: "win32"

If the mouse setting interferes with your operating system's copy and paste ability such as the select to copy feature under X windows, you can revert to the standard behavior by holding shift while selecting text.

Setting your mouse as described also prevents accidental terminal scrolling with the mouse wheel when editing a file remotely and causes Vim to scroll within the current buffer instead.

Thanks to mmmattos for emailing me and providing the motivation for this tip.


Tsung-Kai Chen said...

This is really awesome and helpful, it's a "Life Changing" level tips ^_^

Spectral said...

The 'set term' thing is a bit suspect. That might work, but might not as well. Terminal capabilities and information differ wildly depending on what terminal you're using (xterm, rxvt, microsoft's console, putty,, iTerm, etc.), and getting that properly communicated to the server when you ssh is important. Describing how to do so is beyond the scope of this comment, but in general if you ssh'd to a UNIX machine and your TERM environment variable is sane and your termcap/terminfo are good, you should be fine. Note that most terminal emulators claim they are xterm, and then don't implement all the tiny bugs/quirks of xterm and fall over. If you ssh there a lot, a custom, proper terminfo in your home directory might be beneficial.

The Unix program 'screen' also adds complications. I find I occasionally need to run:
set ttymouse=xterm2
to fix being able to drag inside of vim [for example to resize splits].

(Side note: Did you know that terminal vim can handle 256 color output? Mouse + decent colors (not great, but decent) means I don't ever run gvim. Again, it's all in the TERM, look it up!)

SimonJGreen said...

What term mode would you choose for PuTTY? And do you need to configure putty specially to communicate the mouse?

Same as above also but for OSX?

heimo said...

thanks a lot!

for me (xfce-termina) the following is working:

:set term=xterm
:set mouse=a


Cheap Viagra said...

Really was that mentioned in the last blog?, because this is amazing we deserve an excellent information and this is the best way to get it.

Anonymous said...

Thank you guys. You saved me after hours of Googling...