echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.54k stars 175 forks source link

global keybindings regarding motions (hjkl) #849

Closed thmsaurel closed 2 months ago

thmsaurel commented 2 months ago

Contributing guidelines

Module(s)

mini.basics (can be extended to mini.files and mini.move)

Description

Some keyboard layouts doesn't allow theirs users to use 'hjkl' as efficiently than in qwerty.

I think it would be interesting to have a sub table inside the configuration to add some motions mappings.

config = {
  motions = {
    left  = 'h',
    down  = 'j',
    up    = 'k',
    right = 'l'  
  }
}

It'll impact "mini.basics" as follow:

map({ 'n', 'x' }, config.motions.down, [[v:count == 0 ? 'gj' : 'j']], { expr = true })                                                                                                                                
map({ 'n', 'x' }, config.motions.up,   [[v:count == 0 ? 'gk' : 'k']], { expr = true })                                                                                                                                

map('n', '<C-' .. config.motions.left  .. '>', '<C-w>h', { desc = 'Focus on left window' })                                                                                                                           
map('n', '<C-' .. config.motions.down  .. '>', '<C-w>j', { desc = 'Focus on below window' })                                                                                                                          
map('n', '<C-' .. config.motions.up    .. '>', '<C-w>k', { desc = 'Focus on above window' })                                                                                                                          
map('n', '<C-' .. config.motions.right .. '>', '<C-w>l', { desc = 'Focus on right window' }) 

If this is implemented, I think it'll be nice if this is extended to "mini.files" and "mini.move" (maybe using one global unique table?).

I saw that in previous related issues, you've recommended the langmap option. Like someone said it in #206, "langmap sounds like a workaround/hack". Personally, I don't like the idea of remapping all my keyboard layout to adopt a qwerty compatible one: I'm struggling enough with one layout, I don't want to learn another one (I know it's how you personally using it, sorry :pensive:).

I didn't say it before: thanks for this mini toolkit. I love learning/using it :heart:

echasnovski commented 2 months ago

I didn't say it before: thanks for this mini toolkit. I love learning/using it ❤️

:heart:

I saw that in previous related issues, you've recommended the langmap option. Like someone said it in #206, "langmap sounds like a workaround/hack".

Yes, this is still a recommended solution. I'd not consider this to be a hack mostly because it is more or less a documented solution, as :h langmap contains an example of exchanging the meaning of keys within Latin alphabet.

One thing that it is lacking, though, is indeed that mappings for changing window focus might be different. But the problem with them is that <C-...> keys have a rather convoluted relationship with keyboard layout. For example, CTRL+KEY mostly depends on where that key is placed on QWERTY keyboard and not the current layout: "o" is "щ" in Cyrillic layout, but <C-o> is still CTRL plus "щ".

If this is implemented, I think it'll be nice if this is extended to "mini.files" and "mini.move" (maybe using one global unique table?).

The need to also extend this to other modules is precisely the argument for not adding it and instead suggesting to rely on built-in ways to remap keys. Like 'langmap'.


Closing as not planned.