sponsor Vim development Vim logo Vim Book Ad

basic Tip #471: Bridging the worlds: putting your rodent to work for vim in xterms

 tip karma   Rating 51/18, Viewed by 1590 

created:   May 8, 2003 7:48      complexity:   basic
author:   pagaltzis at gmx dot de      as of Vim:   6.0

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.

 rate this tip  Life Changing Helpful Unfulfilling 

<<Map to quickly swap/exchange arbitrary text | Handy option flag toggler >>

Additional Notes

pagaltzis at gmx dot de, May 8, 2003 7:52
: 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.
[email protected], May 30, 2003 7:43
But how to copy from a browser and paste into an xterm vim?  That's what I want to know...
Anonymous, May 30, 2003 16:15
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.
maurice, June 1, 2003 14:08
Does anybody know of a way to get this working for an aterm?
[email protected], July 18, 2003 16:45
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.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo