Linux Console with gpm & mouse functionality in Vim

2,029 views
Skip to first unread message

John Magolske

unread,
Jul 25, 2008, 1:20:17 AM7/25/08
to vim...@googlegroups.com
While using Vim in a Linux Console, is it possible to use the mouse
for things like re-positioning the text cursor, selecting text to
yank, re-sizing windows by dragging the status line, etc.?

The behavior I see is that I can select text by left-clicking and
dragging, then paste that selection with the middle button. But
this seems to be independent of Vim, as Vim's text cursor stays put
while the mouse cursor is moved around, and the selected text is not
available for yanking.

Also, I find that I cannot re-size windows by dragging or switch focus
by clicking on another tab. These behaviors are available in an Xterm,
is it possible to have them in the Linux Console?

This is version 7.1.293 with the +mouse_gpm feature enabled, running
in Debian unstable. The mouse-related settings in my .vimrc are:

set mouse=a
set mousemodel=popup_setpos


Regards,

John


--
John Magolske
http://B79.net/contact

Tony Mechelynck

unread,
Jul 29, 2008, 10:49:25 AM7/29/08
to vim...@googlegroups.com

To use the mouse in Vim running in the Linux console, you need:
1. a version of Vim compiled with +mouse_gpm
2. the gpm daemon installed and running.

You already have (1). To see if you have (2), type the following at the
shell prompt:

ps -lC gpm

If gpm is running, it will tell you. If it isn't, you (or your sysadmin,
if you aren't one) should arrange to start gpm as part of the boot
sequence, as follows:

First, make sure gpm is installed (e.g., there exists an executable
script named /etc/init.d/gpm). Then, assuming your system uses init,
make sure there are soft links in all the rc1.d, rc2.d, rc3.d, rc5.d and
maybe also rcS.d subdirectories of /etc/init.d, two softlinks in each,
named something like S20gpm and K04gpm, and pointing to ../gpm (i.e., to
gpm in the parent directory init.d). Finally, run "/etc/init.d/gpm
start" to start the daemon. It will automatically be started again at
next boot. All this sysadmin business should of course be done as root.


Best regards,
Tony.
--
It is better never to have been born. But who among us has such luck?
One in a million, perhaps.

John Magolske

unread,
Jul 29, 2008, 2:56:09 PM7/29/08
to vim...@googlegroups.com
* Tony Mechelynck <antoine.m...@gmail.com> [080729 09:39]:

>
> On 25/07/08 07:20, John Magolske wrote:
> > While using Vim in a Linux Console, is it possible to use the mouse
> > for things like re-positioning the text cursor, selecting text to
> > yank, re-sizing windows by dragging the status line, etc.?
> >
> > The behavior I see is that I can select text by left-clicking and
> > dragging, then paste that selection with the middle button. But
> > this seems to be independent of Vim, as Vim's text cursor stays put
> > while the mouse cursor is moved around, and the selected text is not
> > available for yanking.
> >
> > Also, I find that I cannot re-size windows by dragging or switch focus
> > by clicking on another tab. These behaviors are available in an Xterm,
> > is it possible to have them in the Linux Console?
> >
> > This is version 7.1.293 with the +mouse_gpm feature enabled, running
> > in Debian unstable. The mouse-related settings in my .vimrc are:
> >
> > set mouse=a
> > set mousemodel=popup_setpos
> >
> >
> > Regards,
> >
> > John
> >
> >
>
> To use the mouse in Vim running in the Linux console, you need:
> 1. a version of Vim compiled with +mouse_gpm
> 2. the gpm daemon installed and running.
>
> You already have (1). To see if you have (2), type the following at the
> shell prompt:
>
> ps -lC gpm

Thanks for the reply. I have gpm installed, am able to start & stop it
with '/etc/init.d/gpm stop' and '/etc/init.d/gpm start', and also

~ % ps -lC gpm
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
5 S 0 20615 1 0 80 0 - 415 - ? 00:00:00 gpm


The version of Vim I'm using has been compiled with +mouse_gpm

:version
VIM - Vi IMproved 7.1 ... Included patches: 1-293
Huge version with GTK2 GUI.
...
+mouse +mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm
+mouse_netterm +mouse_xterm ...


What I'm wondering is, what sort of support is implied here:

:help gpm
*gpm-mouse*
The GPM mouse is only supported when the |+mouse_gpm| feature was
enabled at compile time. The GPM mouse driver (Linux console) does
not support quadruple clicks.

In Insert mode, when a selection is started, Vim goes into Normal
mode temporarily. When Visual or Select mode ends, it returns to
Insert mode. This is like using CTRL-O in Insert mode. Select mode
is used when the 'selectmode' option contains "mouse".


The following seems to indicate that only with mswin & xterm terminals
can Mouse Control be adjusted:

:help behave
...Set behavior for mouse and selection. Valid arguments are:
mswin MS-Windows behavior
xterm Xterm behavior


As far as I can tell, the gpm mouse has no interaction with Vim in the
Linux console.

Tony Mechelynck

unread,
Jul 29, 2008, 4:54:25 PM7/29/08
to vim...@googlegroups.com
> Thanks for the reply. I have gpm installed, am able to start& stop it

> with '/etc/init.d/gpm stop' and '/etc/init.d/gpm start', and also
>
> ~ % ps -lC gpm
> F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
> 5 S 0 20615 1 0 80 0 - 415 - ? 00:00:00 gpm
>
>
> The version of Vim I'm using has been compiled with +mouse_gpm
>
> :version
> VIM - Vi IMproved 7.1 ... Included patches: 1-293
> Huge version with GTK2 GUI.
> ...
> +mouse +mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm
> +mouse_netterm +mouse_xterm ...
>
>
> What I'm wondering is, what sort of support is implied here:
>
> :help gpm
> *gpm-mouse*
> The GPM mouse is only supported when the |+mouse_gpm| feature was
> enabled at compile time. The GPM mouse driver (Linux console) does
> not support quadruple clicks.
>
> In Insert mode, when a selection is started, Vim goes into Normal
> mode temporarily. When Visual or Select mode ends, it returns to
> Insert mode. This is like using CTRL-O in Insert mode. Select mode
> is used when the 'selectmode' option contains "mouse".
>
>
> The following seems to indicate that only with mswin& xterm terminals

> can Mouse Control be adjusted:
>
> :help behave
> ...Set behavior for mouse and selection. Valid arguments are:
> mswin MS-Windows behavior
> xterm Xterm behavior

Arguments to the ":behave" command are just arbitrary words, they set
four options as shown under ":help behave". It is quite possible to use
":behave mswin" on any terminal, ":behave xterm" on any terminal, or use
neither and set 'selectmode' 'mousemodel' 'keymodel' and 'selection' to
your own favourite settings, different than both.

IOW, ":behave mswin" is equivalent to ":set slm=mouse,key mousem=popup
km=startsel,stopsel sel=exclusive"; ":behave xterm" is equivalent to
":set slm= mousem=extend km= sel=inclusive", in both cases regardless of
which terminal you're actually using. I prefer something else, so I
don't use the ":behave" command: what I use is ":set
selectmode=key,mouse mousemodel=popup keymodel=startsel
selection=inclusive".

>
>
> As far as I can tell, the gpm mouse has no interaction with Vim in the
> Linux console.
>
>
> Regards,
>
> John
>
>

Well, on my Linux console (i.e. when I hit Ctrl-Alt-F2, log in, then
start Vim), it works: e.g., clicking the left mouse button moves the
text cursor (a blinking underscore) to the mouse pointer (a steady
block). Similarly, when I drag the mouse, it highlights the region
dragged-over and --SELECT-- appears at bottom-left.

Any console which can be visible as part of the X-windows screen is not
the Linux console, it is some console emulator (examples are xterm,
konsole and gnome-terminal). The Linux consoles are the pure-text
consoles which have no connection to an X server; the first six, on
/dev/tty1 (Ctrl-Alt-F1) to /dev/tty6 (Ctrl-Alt-F6) can usually be logged
in; /dev/tty10 (on Ctrl-Alt-F10) sometimes displays a system log.


Best regards,
Tony.
--
You should never wear your best trousers when you go out to fight for
freedom and liberty.
-- Henrik Ibsen

Dominique Pelle

unread,
Aug 3, 2008, 8:57:02 AM8/3/08
to vim...@googlegroups.com


Yes, I experience the same thing. I just tried to test gpm mouse
with vim 7.2b.26 BETA on Linux x86 (Ubuntu-8.04). Either I'm
doing something wrong, or it does not work at all. Mouse with
gpm does not work either when using older vim-7.1.138.

- gpm is installed (I can use the mouse in text mode when not
using vim to copy paste text)
- vim is built with gpm support (+mouse_gpm)
- my ~/.vimrc contains "set mouse=a"

Mouse in text mode does not interact with vim. I cannot for example
use the mouse to resize windows or to move cursor in text mode.
Shouldn't GPM mouse let me resize windows in text mode or position
the cursor?

The mouse only works well when using X (in a xterm or gnome-terminal).

Does anybody successfully use the mouse with gpm?

-- Dominique

Markus Heidelberg

unread,
Aug 3, 2008, 10:03:37 AM8/3/08
to vim...@googlegroups.com
Dominique Pelle, 03.08.2008:

>
> On Tue, Jul 29, 2008 at 8:56 PM, John Magolske <b79...@gmail.com> wrote:
> >
> > As far as I can tell, the gpm mouse has no interaction with Vim in the
> > Linux console.
>
> The mouse only works well when using X (in a xterm or gnome-terminal).
>
> Does anybody successfully use the mouse with gpm?

I just tried it and it works for me with 7.1.319 and 7.2b.026, huge version.

/usr/sbin/gpm -m /dev/input/mice -t imps2
or
/usr/sbin/gpm -m /dev/input/mice -t ps2

vim -u NONE
:set mouse=a

Now it works: window resizing, visual selection, cursor positioning, ...

Markus

Tony Mechelynck

unread,
Aug 3, 2008, 10:39:44 AM8/3/08
to vim...@googlegroups.com
>> Thanks for the reply. I have gpm installed, am able to start& stop it

>> with '/etc/init.d/gpm stop' and '/etc/init.d/gpm start', and also
>>
>> ~ % ps -lC gpm
>> F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
>> 5 S 0 20615 1 0 80 0 - 415 - ? 00:00:00 gpm
>>
>>
>> The version of Vim I'm using has been compiled with +mouse_gpm
>>
>> :version
>> VIM - Vi IMproved 7.1 ... Included patches: 1-293
>> Huge version with GTK2 GUI.
>> ...
>> +mouse +mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm
>> +mouse_netterm +mouse_xterm ...
>>
>>
>> What I'm wondering is, what sort of support is implied here:
>>
>> :help gpm
>> *gpm-mouse*
>> The GPM mouse is only supported when the |+mouse_gpm| feature was
>> enabled at compile time. The GPM mouse driver (Linux console) does
>> not support quadruple clicks.
>>
>> In Insert mode, when a selection is started, Vim goes into Normal
>> mode temporarily. When Visual or Select mode ends, it returns to
>> Insert mode. This is like using CTRL-O in Insert mode. Select mode
>> is used when the 'selectmode' option contains "mouse".
>>
>>
>> The following seems to indicate that only with mswin& xterm terminals

>> can Mouse Control be adjusted:
>>
>> :help behave
>> ...Set behavior for mouse and selection. Valid arguments are:
>> mswin MS-Windows behavior
>> xterm Xterm behavior
>>
>>
>> As far as I can tell, the gpm mouse has no interaction with Vim in the
>> Linux console.
>>
>>
>> Regards,
>>
>> John
>
>
> Yes, I experience the same thing. I just tried to test gpm mouse
> with vim 7.2b.26 BETA on Linux x86 (Ubuntu-8.04). Either I'm
> doing something wrong, or it does not work at all. Mouse with
> gpm does not work either when using older vim-7.1.138.
>
> - gpm is installed (I can use the mouse in text mode when not
> using vim to copy paste text)
> - vim is built with gpm support (+mouse_gpm)
> - my ~/.vimrc contains "set mouse=a"
>
> Mouse in text mode does not interact with vim. I cannot for example
> use the mouse to resize windows or to move cursor in text mode.
> Shouldn't GPM mouse let me resize windows in text mode or position
> the cursor?
>
> The mouse only works well when using X (in a xterm or gnome-terminal).
>
> Does anybody successfully use the mouse with gpm?
>
> -- Dominique

WFM: Starting vim in the linux console (e.g. on /dev/tty3, accessed by
Ctrl-Alt-F3) then hitting F1 gives two windows, a [No Name] window and a
help window. So far so good.

With the settings set by my vimrc, the [No Name] window is reduced to
only a status line at the far top, with the help window under it. Moving
the mouse makes the mouse cursor appear; if I move it to the [No Name]
statusline then drag it downward, the statusline comes down with tildes
at left of the empty lines above it. The help window is reduced accordingly.

Clicking the mouse anywhere in a vim window moves the text cursor.

Dragging the mouse in a vim window creates a -- SELECT -- highlighted area.

All this in /dev/tty3 (which has no contact with the X server) with gpm
running and with Vim 7.2b.26. "rpm -qa|grep gpm" answers
gpm-1.20.1-424.1 on this SuSE 11.0 system. (The same rpm|grep command
would work on RedHat, which also uses rpm, but not on Debian or Ubuntu,
which use Debian packages.)

Dominique, shall I send you my vimrc and/or the stdout/stderr log from
my latest "make reconfig"? My config options can be seen near the top of
http://users.skynet.be/antoine.mechelynck/vim/compunix.htm

Gpm is loaded on this computer (by default) by /etc/init.d/rc5.d/S20gpm
which is a link to ../gpm (i.e. /etc/init.d/gpm). Shall I send you a
copy of _that_ script? "which -a gpm" answers (in a root console) with
/usr/sbin/gpm (and doesn't find anything when non-root).


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
94. Now admit it... How many of you have made "modem noises" into
the phone just to see if it was possible? :-)

Dominique Pelle

unread,
Aug 3, 2008, 5:31:53 PM8/3/08
to vim...@googlegroups.com
On Sun, Aug 3, 2008 at 4:39 PM, Tony Mechelynck
<antoine.m...@gmail.com> wrote:

> WFM: Starting vim in the linux console (e.g. on /dev/tty3, accessed by
> Ctrl-Alt-F3) then hitting F1 gives two windows, a [No Name] window and a
> help window. So far so good.
>
> With the settings set by my vimrc, the [No Name] window is reduced to
> only a status line at the far top, with the help window under it. Moving
> the mouse makes the mouse cursor appear; if I move it to the [No Name]
> statusline then drag it downward, the statusline comes down with tildes
> at left of the empty lines above it. The help window is reduced accordingly.
>
> Clicking the mouse anywhere in a vim window moves the text cursor.
>
> Dragging the mouse in a vim window creates a -- SELECT -- highlighted area.
>
> All this in /dev/tty3 (which has no contact with the X server) with gpm
> running and with Vim 7.2b.26. "rpm -qa|grep gpm" answers
> gpm-1.20.1-424.1 on this SuSE 11.0 system. (The same rpm|grep command
> would work on RedHat, which also uses rpm, but not on Debian or Ubuntu,
> which use Debian packages.)
>
> Dominique, shall I send you my vimrc and/or the stdout/stderr log from
> my latest "make reconfig"? My config options can be seen near the top of
> http://users.skynet.be/antoine.mechelynck/vim/compunix.htm

No need to send a ~/.vimrc, it should in theory work with the following
simple ~/.vimrc:

set nocompatible
set mouse=a

But with above ~/.vimrc, mouse only worked in X, but not with gpm in
/dev/tty1 (accessed with control alt F1)

Doing 'ps -efl | grep gpm', I see that gpm is started as:

/usr/sbin/gpm -m /dev/input/mice -t exps2

... which seems OK, since moving the mouse makes the cursor
show up and I can copy paste text with the mouse in text. But
somehow Vim does not interact with the mouse. I tried different
options of gpm (-t ps2, etc) but none of them work.

AH!, I then found the solution: my ~/.bashrc sets TERM=xterm-color.
This breaks Vim in text mode (fair enough). After doing "export TERM=linux",
gpm finally works fine with Vim in text mode.

-- Dominique

John Magolske

unread,
Aug 4, 2008, 1:39:41 AM8/4/08
to vim...@googlegroups.com
* Dominique Pelle <dominiq...@gmail.com> [080803 17:28]:

>
> On Sun, Aug 3, 2008 at 4:39 PM, Tony Mechelynck
> <antoine.m...@gmail.com> wrote:
>
> > WFM: Starting vim in the linux console (e.g. on /dev/tty3, accessed by
> > Ctrl-Alt-F3) then hitting F1 gives two windows, a [No Name] window and a
> > help window. So far so good.
> >
> > With the settings set by my vimrc, the [No Name] window is reduced to
> > only a status line at the far top, with the help window under it. Moving
> > the mouse makes the mouse cursor appear; if I move it to the [No Name]
> > statusline then drag it downward, the statusline comes down with tildes
> > at left of the empty lines above it. The help window is reduced accordingly.
> >
> > Clicking the mouse anywhere in a vim window moves the text cursor.
> >
> > Dragging the mouse in a vim window creates a -- SELECT -- highlighted area.
> >
> > All this in /dev/tty3 (which has no contact with the X server) with gpm
> > running and with Vim 7.2b.26. "rpm -qa|grep gpm" answers
> > gpm-1.20.1-424.1 on this SuSE 11.0 system. (The same rpm|grep command
> > would work on RedHat, which also uses rpm, but not on Debian or Ubuntu,
> > which use Debian packages.)
> >
> > Dominique, shall I send you my vimrc and/or the stdout/stderr log from
> > my latest "make reconfig"? My config options can be seen near the top of
> > http://users.skynet.be/antoine.mechelynck/vim/compunix.htm
>
> No need to send a ~/.vimrc, it should in theory work with the following
> simple ~/.vimrc:
>
> set nocompatible
> set mouse=a

I just tried this simple ~/.vimrc as well, still no luck.

> But with above ~/.vimrc, mouse only worked in X, but not with gpm in
> /dev/tty1 (accessed with control alt F1)
>
> Doing 'ps -efl | grep gpm', I see that gpm is started as:
>
> /usr/sbin/gpm -m /dev/input/mice -t exps2

gpm is started as such on my machine as well. General functionality
is present -- I can select with a left-click & drag, and paste with
a middle-click. But I cannot reposition Vim's text cursor or drag
status bars. Using the above-mentioned two-line ~/.vimrc or starting
Vim with 'vim -u NONE' did not improve the situation. This is in a
Linux framebuffer console (Xwindows not started at all) running in
GNU Screen. Does gpm work with Vim running in a Screen session in a
Linux framebuffer console?

When I quit Screen and run Vim directly in the Linux framebuffer
console, the left-click & drag stops working. I can move the gpm
mouse-cursor around, but when I left-click, the mouse-cursor freezes
and can only be moved again when the left-click is released. Even
with the above two-line ~/.vimrc, there is this 'frozen mouse cursor'
behavior. Commenting out 'set mouse=a' will get rid of the frozen
behavior, as will starting Vim with 'vim -u NONE'. But in both
instances, there is still no ability to reposition Vim's text cursor
or drag status bars.

I also tried renaming the ~/.vim/ directory to make sure the problem
wasn't being caused by any plugins.

> AH!, I then found the solution: my ~/.bashrc sets TERM=xterm-color.
> This breaks Vim in text mode (fair enough). After doing "export
> TERM=linux", gpm finally works fine with Vim in text mode.

While in Screen in a Linux framebuffer console:

% echo $TERM
screen.linux

And while in a Linux framebuffer console:

% echo $TERM
linux

When I start Xwindows and run Vim in an Xterm, all the functionality
is there -- repositioning Vim's text cursor, dragging status bars,
etc. But not while running Vim in the Linux console. Again, this is
Vim 7.1, Huge version, compiled with +mouse_gpm, running in Debian.

Tony Mechelynck

unread,
Aug 4, 2008, 6:23:16 AM8/4/08
to vim...@googlegroups.com
On 03/08/08 23:31, Dominique Pelle wrote:
[...]

> AH!, I then found the solution: my ~/.bashrc sets TERM=xterm-color.
> This breaks Vim in text mode (fair enough). After doing "export TERM=linux",
> gpm finally works fine with Vim in text mode.
>
> -- Dominique

Just make sure you don't set $TERM to linux when running in an xterm...
Maybe remove that TERM= statement altogether? I see TERM=linux in the
Linux console, TERM=xterm in the KDE konsole.

Best regards,
Tony.
--
Somebody ought to cross ball point pens with coat hangers so that the
pens will multiply instead of disappear.

Reply all
Reply to author
Forward
0 new messages