sxhkd: Using Escape to switch back to English and escape
I sometimes type using a non-latin keyboard layout and many vim-like keyboard-based packages. I thought of a conceptually beautiful and simple approach. But I can't implement it.
When in the non-latin layout (arrived at using my regular setxkbmap option toggle) in insert mode one keypress would switch back to my standard layout when exiting to normal mode.
Rather than remap keys within vim (as I need it done globally, for when I'm working in other keyboard-driven environments, with non-latin filenames in ranger, typing in qutebrowser, answering mail in mutt, etc.), I remap the escape key itself to switch back as part of the escape process.
This also avoids having to remember to use a redundant setxkbmap toggle to switch back to standard layout every time. All I'd need to do, if I'm going to write in non-latin that time (which doesn't happen that often) is use the setxkbmap toggle to change to the non-latin. Done writing? Escape back to normal mode and standard keymap in one go.
I tried to chain commands using sxhkd:
@Escape
setxkbmap -layout uk & xcape..... & escape
That command (minus the & escape at the end) works in my .xprofile, so no problem with the command itself, just my implementation within sxhkd.
It switches back to English but (I think) it creates an infinite loop, where Escape changes the layout, becomes escape and changes the layout, becomes escape and changes... But never actually acts as escape.
Any other ideas? Can this work? Could this work if I set escape as mod5 first? Let me try...
EDIT to add. Essentially what I'm looking for is a way to issue an escape keystroke (eg. Escape, ^], or similar), so I can chain that to the end of my sxhkd.
Edited 24 Sep 2019. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 5 · 100% up
- Kind
- Text
- ID
- d8iluc
7 comments
make this script somewhere and the use it on sxhkd
change to "us" and "gr" to your language
on sxhkd then
@Escape
./layout.sh
I'll try it when I get home, but it seems that just changes the language on the Escape release. No? It wouldn't escape back into normal mode (in all vimlike environments) as well.
Somewhere in there I need a "Issue ^] keysym" command, or something similar.
this script toggles the between the languages on each press i dont have vim to to test what you want to do but you can put the vim command after "setxkbmap -layout us" && vim-command
I have done something similar but only in vim: us_layout in normal mode and it would always keep track of what was the last layout used in insert mode, and would just set it back while entering insert mode. That has been more than enough for me because anything that span more than a couple of line I would end up editing anyway, so why not write into vim?
Can't help with your problem, but I am currently giving Sway-wm a try and found this:
This solution sounds way more elegant to me than the hacks I've been doing to keep my keybinds work across multiple keyboard layouts. Maybe there's something similar with sxhkd? Good luck with your issue.
That would be nice, but I haven't found it yet!
EDIT to add. The whole reason I want it as a global key binding is I'll often be chatting to someone in another language, escape without looking at the screen, try to get another window up and lo and behold, I'm still where I was when I escaped into normal mode.
Or I'll change a filename in another language, escape, and again, forget to change back to English to be able to move around ranger.
Or search on qutebrowser, escape, and again, can't use my keyboard in normal mode until I switch to English.
It's not much, and I can deal with it haha but it doesn't seem like an impossible task, and in the vein of vimlike efficiency, reducing two separate tasks involving 3 keys (escape and change keymap) to one simple keystroke seems like a great idea. One that I'm willing to sacrifice a miniscule amount of processing power for (when in English, pressing escape will pointlessly put me back into English, although, and although an if block could bypass that too, it's essentially making the simple escape key a little more complex).
Source: https://m.habr.com/ru/post/98393/ Add to your .vimrc
Change russiuan-jcukenwin to your layout. Change layout with
ctrl+^.:help keymapfor more info.Thanks for the idea, I have something similar implemented, but it's still just limited to vim. I want to implement a change globally. Using xmodmap, sxhkd or similar.