mini.nvim icon indicating copy to clipboard operation
mini.nvim copied to clipboard

global keybindings regarding motions (hjkl)

Open thmsaurel opened this issue 2 years ago • 4 comments

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:

thmsaurel avatar May 02 '24 02:05 thmsaurel

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.

echasnovski avatar May 02 '24 08:05 echasnovski

@echasnovski Hi! Is there a way to override only the j and k mappings in mini.files?

axkirillov avatar Mar 08 '25 10:03 axkirillov

@echasnovski Hi! Is there a way to override only the j and k mappings in mini.files?

I am not sure I understand the question. Could you elaborate, please?

It is possible to disable automatic creation of buffer-local variables by setting them to '' and create any buffer-local mappings like this.

echasnovski avatar Mar 08 '25 11:03 echasnovski

@echasnovski Nice, thank you! That answers my question 🙂

axkirillov avatar Mar 08 '25 11:03 axkirillov