You are not logged in.

#1 2009-10-23 13:14:10

zoqaeski
Member
From: /earth/australia/.
Registered: 2009-09-30
Posts: 124

Vim style keybindings in GTK apps and Openbox

Hello all
I've been using Openbox for a while now, I use Vim all the time for most of my work, and I've enabled Vimperator for Firefox as I found that once you know the Vim keybindings, it becomes much quicker to do things without a mouse.

Problem is, being so used to these keybindings I find that I'll unintentionally search for something starting with 'j' when I want to scroll down (i.e. with Thunar). Does anyone know of a method to enable a Vim mode for GTK+? I've almost set up a Vim mode with my Openbox rc.xml, but so far GTK has resisted my efforts to change it, which is a real shame because they provided an Emacs mode =/

cheers for anyone who can offer suggestions smile

Offline

#2 2009-10-23 14:21:41

alterecco
Member
Registered: 2009-07-13
Posts: 152

Re: Vim style keybindings in GTK apps and Openbox

It is not a perfect solution, but with a little xmodmapping you can set up a scheme that gives you hjkl (with a modifier) in almost any app (almost). It even gives you hjkl in insert mode in vim, which i find particularly handy.

Here is my xmodmap file which accomplishes this for my keyboard. Please don't use it directly as it may not be compatible with every keyboard. It is here as an example of a keyboard layout using Mode_switch. I have added some comments wher things may not be clear.

!----------------------------------------------------------------------------
! file:     ~/.xmodmap
! vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=xmodmap:
!----------------------------------------------------------------------------

!----------------------------------------------------------------------------
! Modifiers
!----------------------------------------------------------------------------

! clear the modifiers and locks
! remember to add them after all keysyms have been assigned
clear Shift
clear Control
clear Mod1
clear Mod2
clear Mod3
clear Mod4
clear Mod5

! Shift + Shift initiates ShiftLock mode, which allows
! for shifted behaviour on all keys.
! This can act as replacement for Caps_Lock.
! Toggle it off with one single shift keypress.
keycode 50 = Shift_L Shift_Lock
keycode 62 = Shift_R Shift_Lock

! standard Left Alt, except I prefer meta over alt
keycode 64  = Meta_L Alt_L

! "Menu" key, shifts us into the next group permanenty (toggle)
! I actually don't use this myself, but left it here for future study.
! keycode 135 = ISO_Next_Group ISO_Prev_Group
keycode 135 = Super_R

! AltGr is Multi_key for those fancy compose chars
! have a look at .Xcompose for more info
keycode 108 = Multi_key Meta_R

! standard Control and Super keys
keycode  37 =   Control_L
keycode 105 =   Control_R
keycode 133 =   Super_L

! Caps_Lock is Mode_switch. Mode_switch sends keys from
! one group above the current (shifted and unshifted).
keycode  66 =   Mode_switch

! Only use two groups, to keeps switching sane.
! You can add several groups, but I have not tried with more than 4

!               |---   Group 1   ---|                   |---   Group 2   ---|

!----------------------------------------------------------------------------
! Special Keys
!----------------------------------------------------------------------------
keycode   9 =   Escape
keycode  23 =   Tab             ISO_Left_Tab
keycode  22 =   BackSpace       Terminate_Server
keycode  36 =   Return
keycode  65 =   space

!----------------------------------------------------------------------------
! Num Keys
!----------------------------------------------------------------------------
keycode  49 =   grave           asciitilde
keycode  10 =   1               exclam
keycode  11 =   2               at
keycode  12 =   3               numbersign
keycode  13 =   4               dollar
keycode  14 =   5               percent
keycode  15 =   6               asciicircum
keycode  16 =   7               ampersand
keycode  17 =   8               asterisk
keycode  18 =   9               parenleft
keycode  19 =   0               parenright
keycode  20 =   minus           underscore
keycode  21 =   equal           plus

!----------------------------------------------------------------------------
! Upper Row
!----------------------------------------------------------------------------
keycode  24 =   q               Q
keycode  25 =   w               W
keycode  26 =   e               E
keycode  27 =   r               R
keycode  28 =   t               T
keycode  29 =   y               Y
keycode  30 =   u               U                       Prior
keycode  31 =   i               I                       Home
keycode  32 =   o               O                       End
keycode  33 =   p               P
keycode  34 =   bracketleft     braceleft               Escape
keycode  35 =   bracketright    braceright

!----------------------------------------------------------------------------
! Home Row
!----------------------------------------------------------------------------
keycode  38 =   a               A
keycode  39 =   s               S
keycode  40 =   d               D                       Delete
keycode  41 =   f               F
keycode  42 =   g               G
keycode  43 =   h               H                       Left
keycode  44 =   j               J                       Down
keycode  45 =   k               K                       Up
keycode  46 =   l               L                       Right
keycode  47 =   semicolon       colon
keycode  48 =   apostrophe      quotedbl
keycode  51 =   backslash       bar

!----------------------------------------------------------------------------
! Lower Row
!----------------------------------------------------------------------------
keycode  94 =   less            greater
keycode  52 =   z               Z
keycode  53 =   x               X
keycode  54 =   c               C
keycode  55 =   v               V
keycode  56 =   b               B                       BackSpace
keycode  57 =   n               N                       Next
keycode  58 =   m               M
keycode  59 =   comma           less
keycode  60 =   period          greater
keycode  61 =   slash           question

!----------------------------------------------------------------------------
! F keys
!----------------------------------------------------------------------------
keycode  67 =   F1              XF86_Switch_VT_1
keycode  68 =   F2              XF86_Switch_VT_2
keycode  69 =   F3              XF86_Switch_VT_3
keycode  70 =   F4              XF86_Switch_VT_4
keycode  71 =   F5              XF86_Switch_VT_5
keycode  72 =   F6              XF86_Switch_VT_6
keycode  73 =   F7              XF86_Switch_VT_7
keycode  74 =   F8              XF86_Switch_VT_8
keycode  75 =   F9              XF86_Switch_VT_9
keycode  76 =   F10             XF86_Switch_VT_10
keycode  95 =   F11             XF86_Switch_VT_11
keycode  96 =   F12             XF86_Switch_VT_12

!----------------------------------------------------------------------------
! Fn F keys
!----------------------------------------------------------------------------
keycode  77 =   Num_Lock        Pointer_EnableKeys
keycode  78 =   Scroll_Lock

!----------------------------------------------------------------------------
! KP Keys / Fn keys
!----------------------------------------------------------------------------
keycode  87 =   KP_End          KP_1
keycode  88 =   KP_Down         KP_2
keycode  89 =   KP_Next         KP_3
keycode  83 =   KP_Left         KP_4
keycode  84 =   KP_Begin        KP_5
keycode  85 =   KP_Right        KP_6
keycode  79 =   KP_Home         KP_7
keycode  80 =   KP_Up           KP_8
keycode  81 =   KP_Prior        KP_9
keycode  90 =   KP_Insert       KP_0
keycode  86 =   KP_Add          XF86_Next_VMode
keycode  82 =   KP_Subtract     XF86_Prev_VMode
keycode  91 =   KP_Delete       KP_Decimal
keycode  63 =   KP_Multiply     XF86_ClearGrab
keycode 106 =   KP_Divide       XF86_Ungrab

!----------------------------------------------------------------------------
! Print, Pause, Insert, Delete
!----------------------------------------------------------------------------
keycode 107 =   Print           Sys_Req
keycode 127 =   Pause           Break
keycode 118 =   Insert
keycode 119 =   Delete

!----------------------------------------------------------------------------
! Home, PgUp, PgDown, End
!----------------------------------------------------------------------------
keycode 110 =   Home
keycode 112 =   Prior
keycode 117 =   Next
keycode 115 =   End

!----------------------------------------------------------------------------
! Fn+Home/PgUp/PgDown/End
!----------------------------------------------------------------------------
keycode 172 =   XF86AudioPlay
keycode 174 =   XF86AudioStop
keycode 173 =   XF86AudioPrev
keycode 171 =   XF86AudioNext

!----------------------------------------------------------------------------
! Cursors
!----------------------------------------------------------------------------
keycode 113 =   Left
keycode 111 =   Up
keycode 114 =   Right
keycode 116 =   Down

!----------------------------------------------------------------------------
! XF86 Keys
!----------------------------------------------------------------------------

! Fn+F8
keycode 121 =   XF86AudioMute
! Fn+F4
keycode 150 =   XF86Sleep

! Builtin volume keys
keycode 122 =   XF86AudioLowerVolume
keycode 123 =   XF86AudioRaiseVolume


! Brightness controls on Fn key
keycode 232 =  XF86MonBrightnessDown
keycode 233 =  XF86MonBrightnessUp
! 126 is Brighness up, when it can go no futher
keycode 126 =  NoSymbol


!----------------------------------------------------------------------------
! Reassign Modifiers
!----------------------------------------------------------------------------
add Shift = Shift_L Shift_R
add Control = Control_L Control_R
add Mod1 = Alt_L Meta_L
add Mod2 = Num_Lock
add Mod4 = Super_L Super_R

Let me know if there is something that is not clear

Last edited by alterecco (2009-10-23 14:24:14)

Offline

#3 2009-10-28 05:19:02

zoqaeski
Member
From: /earth/australia/.
Registered: 2009-09-30
Posts: 124

Re: Vim style keybindings in GTK apps and Openbox

The xmodmap idea sounds interesting, but do you know of a way in which you could generate one based on your existing keymap? Manually figuring it all out would be a nuisance =/ . Also, a lot of my keybindings in Openbox use the Super/Windows key to adjust window settings, so using that key might cause conflicts.

Offline

#4 2009-10-28 05:31:52

alterecco
Member
Registered: 2009-07-13
Posts: 152

Re: Vim style keybindings in GTK apps and Openbox

xmodmap -pke > ~/xmodmap

The above will provide you with you current keymappings.

Coming up with a good scheme for using you kb requires some forethought. Depends on what applications you use and what tasks you preform...

have fun! .]

Offline

#5 2009-10-28 09:31:28

droog
Member
Registered: 2004-11-18
Posts: 877

Re: Vim style keybindings in GTK apps and Openbox

alterecco wrote:

It even gives you hjkl in insert mode in vim, which i find particularly handy.

So in insert mode instead of typing hjkl it moves the cursor, why would you want that?
hope you don't need to actually use those letters in what you're typing?

I would just patch thunar, I made a patch for rox-filer awhile ago that does this. It's pretty easy to do.

Offline

#6 2009-10-28 10:48:50

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Vim style keybindings in GTK apps and Openbox

droog wrote:

hope you don't need to actually use those letters in what you're typing?

Was about to say... big_smile


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#7 2009-10-28 11:38:24

the_isz
Member
Registered: 2009-04-14
Posts: 269

Re: Vim style keybindings in GTK apps and Openbox

droog wrote:
alterecco wrote:

It even gives you hjkl in insert mode in vim, which i find particularly handy.

So in insert mode instead of typing hjkl it moves the cursor, why would you want that?
hope you don't need to actually use those letters in what you're typing?

I'm pretty sure he's using an overlay, so that either [ModKey]+j moves left or
[ModKey] toggles modes, so that in one of them j moves left and in the other j
prints that character.

Using different keys to move the cursor in insert and normal mode is one of the
very few things that make me prefer emacs over vim, which is why I find the idea
of overlays pretty good. As I only started using Vim, I'll stick to the Vim way
for now (not moving the cursor in insert mode except through normal typing).

Hope I didn't miss/ruin a joke, though tongue

Last edited by the_isz (2009-10-28 11:41:34)

Offline

#8 2009-10-28 12:42:01

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Vim style keybindings in GTK apps and Openbox

Well..wouldn't it be easier to just hit escape then? Why bother with system wide settings for vim if you are still required to press something in order to move through text?


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#9 2009-10-28 12:54:12

the_isz
Member
Registered: 2009-04-14
Posts: 269

Re: Vim style keybindings in GTK apps and Openbox

Because that way is more intuitive to some when correcting typing errors or
inserting missing letters just a few cursor spaces away. I don't say it's an
ultimate solution, it's just closer to how other editors behave.

Offline

#10 2009-10-28 15:10:49

alterecco
Member
Registered: 2009-07-13
Posts: 152

Re: Vim style keybindings in GTK apps and Openbox

Lich wrote:

Well..wouldn't it be easier to just hit escape then? Why bother with system wide settings for vim if you are still required to press something in order to move through text?

All i can say is that jamming left pinky on caps_lock and using hjkl is magnitudes faster for me than hitting escape and doing the same. As an added benefit, I can use them in browser text fields, and any other app that does not let me make native scroll rebindings or require modeless textinput. But hey, mileage may vary...

Last edited by alterecco (2009-10-28 15:16:06)

Offline

#11 2009-10-28 15:14:59

alterecco
Member
Registered: 2009-07-13
Posts: 152

Re: Vim style keybindings in GTK apps and Openbox

droog wrote:
alterecco wrote:

It even gives you hjkl in insert mode in vim, which i find particularly handy.

So in insert mode instead of typing hjkl it moves the cursor, why would you want that?
hope you don't need to actually use those letters in what you're typing?

I would just patch thunar, I made a patch for rox-filer awhile ago that does this. It's pretty easy to do.

Just for good order, since perhaps I wan't clear enough about this.

It would be insane to bind hjkl to the arrow keys, I can agree on that, which is why i have them bound when pressing a modifier.

Offline

#12 2009-10-29 04:25:21

zoqaeski
Member
From: /earth/australia/.
Registered: 2009-09-30
Posts: 124

Re: Vim style keybindings in GTK apps and Openbox

I think I've come up with a scheme that I like, but I can't test it because it isn't loading or being loaded, even after a reboot. GNOME still controls some of my underlying settings; in effect I'm using Openbox on top of GNOME with the default file browser, terminal, panel, text editor and music player replaced. Here's my ~/.xmodmap, perhaps there are errors in it, or do I need to explicitly state in another config file that it is to be loaded?

Edit
I had Mode_switch as mode_Switch, which was a slight issue and is now fixed. And my Openbox configuration had a few bugs because I had added h,j,k,l navigation to it, but now that Mode_switch is enabled I removed them; in the process, I accidentally moved the commands outside of a keychain =/

Last edited by zoqaeski (2009-10-29 05:39:12)

Offline

#13 2009-10-29 16:10:28

alterecco
Member
Registered: 2009-07-13
Posts: 152

Re: Vim style keybindings in GTK apps and Openbox

You can always load an xmodmap file just by calling "xmodmap filename"

If you have not done so already, I strongly recommend reading the xmodmap man pages. Also creating a default xmodmap with "xmodmap -pke" to keep around while testing your new scheme is also handy.

When you want to load the xmodmap by default just run it from your .xinitrc

Offline

Board footer

Powered by FluxBB