Thursday July 27, 2006 at 15:16
Subject: Mouse support under vim.
Keywords:
Technical, vim
Posted by: Sean Reifschneider
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.
(Post Reply)
(Post Reply)
| Comment |
Author:
unikuser Subject: vim paste works fine |
I do not quiet understand what you are saying. what is pasted in console is depends on what console you use and how you configure that. I use Konsole and everything works as I like here. In vim you can get what ever you want.
"*p (paste from primary)
"+gP (paste from clipboard )
You can map these to what ever you want
| Comment |
Author:
Sean Reifschneider Subject: Not sure what more I can say... |
If the original, detailed, description of the problem didn't get you to understand the issue, I'm not sure there's much more I can say about it. After more time working with this, I've determined that vim is just broken for my use-case, and that the developers aren't interested in fixing this case.
So I've just decided to disable the mouse support, because it was annoying me more than it was helping, and manually enable/disable "paste" mode. It's annoying, but less annoying than vim's mouse support, to me.
The closest I got to it working as I expect, based on how my other applications work, is that I have to use shift-left-click+drag to select the region (just left click+drag will move my cursor around), but some other applications were not happy with a shift plus click. I really just don't want to have to think about whether my terminal is in vi or at the shell prompt or whatever when I select some text.
So, glad it works for you, but I am not happy with the way the mouse support works. I just wish vim could take an action on detecting a bunch of input in a short time, and set paste mode then. That would be ideal for me.