Your Linux Data Center Experts

vim has a nice feature where it can integrate with a mouse, even under xterm and similar terminals. Some of these features I really don't like, things like having the text cursor move to where the mouse cursor is when you click. In fact, I don't like most of the mouse support, but there is one thing I'd really like: automatic paste support.

In gvim (the GUI version), and to a limited extent in “vim”, you can do “set mouse=a” and get the ability to click around in the text display, and move the cursor, moving around and resizing windows (which I think would be nice, if I used Windows more, because I've never really gotten familiar with Window commands), etc. It also has an option to do “set paste” when you paste text in. “paste” mode disables things like word wrap and auto-indent, so your pasted text doesn't get munged.

However, in the default terminal-mode vim builds on Ubuntu and FC5 (and probably others), the terminal mode vi is built without X support (not surprisingly), which means that clicking the paste button (middle mouse button in most cases) pastes the vim cut buffer, not the X selection. Fricking annoying!

There is a workaround that Gary Johnson on the vim-devel list was helpful enough to point out: you can run “gvim -v” to run gvim in a terminal session. This allows vim to see the X selection buffer instead of not. If you select some text in vim, it will move your text cursor, which annoys me (because no other application in an xterm works that way), but you can work around that by using shift-left mouse to select text. Still annoying, but functional.

I'm not quite sure yet whether it's worth it to have to use shift-left mouse to select, instead of doing “set paste” before pasting. However, someone who was less picky than me may really like this setup. So, try “gvim -v” and “set mouse=a”.

I had gone on vim-devel to suggest that they automatically detect paste by watching how many characters they had received in the last, say, 100ms, and if it was over a certain threshold setting “paste” or similar, then doing the inverse when they noticed it had stopped. They already have code in there to do that to try to figure out if an escape-sequence has been sent, or if the user pressed Esc and typed some stuff, so it should be easy, I just haven't had time to dig into vim code, and am unlikely to any time soon.

Another idea I had was that it would be nice to have the option for paste to use a “soft auto-indent” instead of just shutting off auto-indent. I will often paste in command output while indented in an e-mail message, as a sample session. With paste, at least my lines don't get all munged, but it would be nice if it noticed the current indentation level and considered that to be the base indentation for the paste to happen at. Right now, all additional lines get pasted against the left margin.

comments powered by Disqus

Join our other satisfied clients. Contact us today.