⬆️ ⬇️

Vim-like control with xmodmap

The implementation of the Vim-like control described in the previous article has a couple of significant drawbacks: it fits only to the GTK environment and a modifier key is required to move the cursor through the edited elements. It turns out, in general, not quite and Vim-like, as was rightly noted in the comments. Therefore, it was decided to describe his experience in building a keyboard-like keyboard environment using xmodmap and the command shell.





The first thing to do is create a directory for xmodmap resource files, for example ~ / .keytoggle.



The second is to remove the current keyboard layout:
$xmodmap -pke >~/.keytoggle/input-keymap.rc 


')

Next, create a file

~ / .keytoggle / control-keymap.rc
 !{{{ override latin 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 keycode 31 = i I keycode 32 = o O keycode 33 = p P keycode 34 = bracketleft keycode 35 = bracketright keycode 38 = a A keycode 39 = s S keycode 40 = d D keycode 41 = f F keycode 42 = g G keycode 43 = h H keycode 44 = j J keycode 45 = k K keycode 46 = l L keycode 47 = semicolon colon keycode 48 = apostrophe quotedbl keycode 49 = Escape Escape Escape Escape !keycode 49 = grave asciitilde keycode 52 = z Z keycode 53 = x X keycode 54 = c C keycode 55 = v V keycode 56 = b B keycode 57 = n N keycode 58 = m M keycode 59 = comma less keycode 60 = period greater !}}} !{{{ override numbers ! keycode 10 = 1 exclam 1 1 exclam ! keycode 11 = 2 at 2 2 quotedbl ! keycode 12 = 3 numbersign 3 3 numerosign ! keycode 13 = 4 dollar 4 4 semicolon ! keycode 14 = 5 percent 5 5 percent ! keycode 15 = 6 asciicircum 6 6 colon ! keycode 16 = 7 ampersand 7 7 question ! keycode 17 = 8 asterisk 8 8 asterisk ! keycode 18 = 9 parenleft 9 9 parenleft ! keycode 19 = 0 parenright 0 0 parenright !}}} !{{{ bindings !esc keycode 9 = grave asciitilde !h keycode 43 = Left Left !j keycode 44 = Down Down !k keycode 45 = Up Up !l keycode 46 = Right Right !p keycode 33 = Prior Prior !n keycode 57 = Next Next !d !keycode 40 = Delete Delete ![ keycode 34 = Home Home !] keycode 35 = End End !m keycode 58 = F7 !}}} 




All the bindings are described in the comments, I will note only that in my case the REMAPs Ctrl-CapsLock, Esc- ~ and some more personal reassignments are used.



Actually, the switching of input-editing modes is performed simply by performing xmodmap with the resource we need. You can hang on a couple of hotkeys, and you can write a script like this:

~ / bin / kt
 #!/bin/bash DIR="$HOME/.keytoggle" function toggle(){ if [ -e $DIR/lock ] then xmodmap $DIR/input-keymap.rc rm $DIR/lock else xmodmap $DIR/control-keymap.rc touch $DIR/lock fi } function show(){ if [ -e $DIR/lock ] then echo -- else echo -- INSERT -- fi } case $1 in t) toggle;; *) show;; esac 




The call “kt t” changes the mode, without arguments - gives to standard output a state that can be displayed in the status line of the window manager, via osd_cat or any other notifier to taste. For example, like this:

~ / .ion3 / main / cfg_statusbar.lua
 mod_statusbar.create{ screen=0, pos='bl', fullsize=true, systray=true, template="%date".. "[ %>workspace_name ]".. "[ %exec_xkb ]".. "[ M: %exec_mounted ]".. "%filler".. "%>exec_lt" } mod_statusbar.launch_statusd{ load={ update_interval=10*1000, }, date={ date_format='[ %H:%M ]', }, exec = { lt={ program = "mps s", retry_delay = 3 * 1000, }, xkb={ program = "kt", retry_delay = 1 * 1000, }, mounted={ program ="fmounted", retry_delay=2 * 1000, }, } } 




And the final chord - hang up switching modes on the hotkey. For example, my switch was assigned to <Super_R>:

 $grep 'kt t' ~/.ion3/main/cfg_ion.lua kpress("Super_R", "ioncore.exec_on(_, 'kt t')"), 




Such an implementation does not depend on the used toolkit, but it will also greatly please Vim lovers, who have to work a lot with Windows via rdp, I think.



Why did I give up on all this? Virtually all the software I need every day has an out-of-the-box Vim style control. As a result, the need for additional keyboard mode simply disappeared. It was replaced by the mod1 + [hjklqw] combinations described in the previous article in some input fields (webkit, dwb command line). By the way, I use these shortcuts when editing in Vim - sometimes it's faster than changing modes.

Source: https://habr.com/ru/post/266745/



All Articles