Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #471 - Using the mouse for Vim in an xterm

Created: May 8, 2003 7:48 Complexity: basic Author: pagaltzis at gmx dot de Version: 6.0 Karma: 55/19 Imported from: Tip#471

If, like me, you don't want to use the GUI vim because you work in an xterm most of the time anyway, you may be annoyed at the shortcomings this presents. For example, during my webbrowsing, I'll often fire up vim in one of the already lying around xterms to conveniently write a long text (such as this one), and then paste from vim into a textfield on a HTML form in the browser.

The first problem is caused by line numbering, which I keep enabled at all times.

:set number 

:help 'number'

Normally, if you try to copy text out of the xterm that vim is running in, you'll get the text as well as the numbers. The GUI version gets this right: it only selects the text, keeping the line numbers out of the picture. But I don't want the GUI version. So instead, I added this to my vimrc:

:set mouse=a 

Much better. You can also selectively enable mouse support for specific modes only by using something other than 'a' (for 'all'). :help 'mouse'


Now although I'm more of a keyboarder, when I juggle text between X apps (or maybe between xterms), it's just more convenient and efficient to keep my hands on my mouse, since they're there anyway. Now, if you own a moderately recent model, you'll know this lovely little wheel they have (which usually also doubles as mouse button 2). Rolling it scrolls the window in GUI vim, which simplifies life when selecting several, distant passages to paste one after the other. But I don't want to use the GUI vim - you can imagine my delight when I ran across this in the vim documentation: :help 'wheel'

It involves adding a couple mappings to your vimrc and corresponding VT100 translations to your .Xresources file as a prerequisite. Don't forget

$ xrdb -load .Xresources 

after you edit the file. The running xterm will not heed the changes; you need to open a new one to see the effect.

The wheel may not work with the mappings as described in the helpfile. They worked without a hitch for me at first (using Xfree 4.1 then), but broke after I upgraded my distro. Whether it was the switch to 4.3 on this binary has been built with different options, I don't know. At any rate, I had to experiment a bit with the list from :help keycodes

After a bit of trial and error, I finally fixed them by substituting <xCSI> for <M-Esc>:

:map <xCSI>[62~ <MouseDown> 
" etc 
" ... 

Done. Load a large text file and marvel at mousewheel scrolling.

Comments

Whether it was the switch to 4.3 on this binary has been built with different options, I don't know.

That is, of course:

Whether it was the switch to 4.3 *or* this binary has been built with different options, I don't know.

pagaltzis at gmx dot de , May 8, 2003 7:52


But how to copy from a browser and paste into an xterm vim? That's what I want to know...

waxmop--AT--sarcastic-horse.com , May 30, 2003 7:43


re: pasting into an xterm vim..

Select text in your browser, goto vim, :set paste, insert mode, middle click (button 2)

If you don't set paste mode, you're probably not going to be happy with the results due to indendation and whatnot.. I bound F11 to toggle paste mode, in both insert mode and normal mode. From my .vimrc:

" F11 to toggle paste mode

map <F11> :set invpaste<CR> 
set pastetoggle=<F11> 


Hope this helps.

Anonymous , May 30, 2003 16:15


Does anybody know of a way to get this working for an aterm?


maurice , June 1, 2003 14:08


Re how to make it work in an aterm... Have you tried :set mouse=a ? It's worked fine for ages for me in an aterm.

deeni--AT--altern.org , July 18, 2003 16:45


If you want "set mouse=a" to work over SSH, just use the '-X' option when using SSH.

vim--AT--vankuik.nl , May 2, 2006 5:40


Advertisement