Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: make normal mode agnostic of keyboard layout #2151

Open
maximbaz opened this Issue Jun 23, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@maximbaz
Copy link
Contributor

maximbaz commented Jun 23, 2018

I have English and Russian keyboard layouts (with Latin and Cyrillic letters respectively), and kakoune is unusable in normal layout when Russian layout is active. To start typing text on a new line, I have to first switch to English layout, press "o", then switch to Russian layout and only then start typing the text. As you can imagine, this is very annoying.

Vim solves this using langremap configuration, where I can configure that in normal mode Cyrillic "щ" should correspond to Latin "o" (these keys are located in the same place on the physical keyboard), so I can press the "o" key in both English and Russian layouts and vim will do the same action.

This should also respect my own mappings, so if I configure a new mapping map global user o :echo 'foo<ret>', this mapping should also be triggered when I press the "o" key in Russian layout (so the Cyrillic "щ") — I don't want to configure all of my mappings twice.

I'm not married to langremap approach, if you have better ideas how to support my scenario, I am happy to hear them.

@Screwtapello

This comment has been minimized.

Copy link
Contributor

Screwtapello commented Jun 23, 2018

Because Kakoune is a terminal application, it only knows about Unicode characters, not about keys: it doesn't know what keyboard layout you're using, what physical key "щ" corresponds to, or what character that key would produce in English layout, so it's not really possible to solve this in a way that Just Works (although perhaps a GUI-based frontend could do this, someday).

As you've probably discovered, it's not possible to use map to do this, since map always maps directly to underlying commands, not to other mappings.

It might be useful for Kakoune to have an extra map "mode" that is always applied before the actual current mode, to cover this use-case:

map global ovelay щ o
map global user o ":echo foo<ret>"

Alternatively, a special map option whose keys are locale codes like en_US or ru_RU, and whose values are strings where each odd character gets automatically mapped to the following even character outside of insert mode. That way, Kakoune could ship with default config like:

set-option -add global langmap "ru_RU=щo"

...and if Kakoune was started in a known locale, it would Just Work... assuming each locale has exactly one keyboard layout, or at least one popular keyboard layout, and nobody ever mapped anything to non-Latin keys.

@maximbaz

This comment has been minimized.

Copy link
Contributor Author

maximbaz commented Jun 23, 2018

I appreciate you desire to make things Just Work, but the assumptions you mentioned... I don't think we can expect them to hold 🙂 Maybe just follow the vim's approach then and make users define their langmaps without binding to a locale? We can have a Wiki page where people share their langmaps, for simple copy-paste.

Vim has two ways to configure langmap, either you define a list of "from-to" character pairs separated by comma, or you can group the characters in longer strings. This is my full langmap definition in vim:

set langmap+=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ " Cyrillic layout in normal mode
set langmap+=фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz " Cyrillic layout in normal mode
set langmap+=ЖжЭэХхЪъ;\:\;\"\'{[}]                                 " Cyrillic layout in normal mode
@andreyorst

This comment has been minimized.

Copy link
Contributor

andreyorst commented Oct 16, 2018

Vim also supports this:

set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0

Which means that you can switch layout within Vim only. And when you're in insert mode, you use desired layout, but if you're in normal mode, EN keymap is used. I was struggling with Russian layout too, and this fix works very well

@FlyingWombat

This comment has been minimized.

Copy link

FlyingWombat commented Feb 25, 2019

I agree with the suggestion by @Screwtapello to have a special 'langmap' mode, that when activated is always applied over the current actual mode (except insert mode). This would be useful not only for language maps, but also for non-standard keyboard layouts, such as Dvorak.

I'd also like to mention, such 'langmap' feature should keep recorded macros in mind. That way, the macros are still recorded in the editing language (instead of Cyrillic), and stay consistent whether 'langmap' is on or off.

Would Kakoune's design philosophy -- to have a 1-to-1 relationship between scripted editing and interactive editing -- be against this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.