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

how to remap alt key in vimrc #17

Open
yunlongYoung opened this issue Feb 23, 2021 · 3 comments
Open

how to remap alt key in vimrc #17

yunlongYoung opened this issue Feb 23, 2021 · 3 comments

Comments

@yunlongYoung
Copy link

yunlongYoung commented Feb 23, 2021

{
    "inoremap": [
        ["<a-i>", "<Up>"],
        ["<a-j>", "<Left>"],
        ["<a-k>", "<Down>"],
        ["<a-l>", "<Right>"],
    ],
//   i               ↑
//j  k  l         ←  ↓  →
        "nnoremap": [
            ["h", "i"],
            ["j", "h"],
            ["k", "j"],
            ["i", "k"],
            ["H", "I"],
            ["J", "H"],
            ["K", "J"],
            ["I", "K"],
        ],
}

Alt key can not remap, how to remap it?

And I found a bug using jupyterlab 3.0.8 and vimrc 0.5.2 on WSL2 Ubuntu 20.04 Anaconda(just use pip installed, do not install the node.js).
When I reopen the Jupyterlab, all the remapping will not work. And I add comments into vimrc(otherwise can not save change), and remapping will work again, but when i use jupyterlab for a while, and it will not work again. I need add a comment the vimrc again to make it run.

Seems there is a backend process always get out of running, maybe in your or jupyterlab's code.

@ianhi
Copy link
Owner

ianhi commented Feb 23, 2021

Hi @yunlongYoung

Alt key can not remap, how to remap it?

I played around with this and it's confusing that the remappings you have don't work. However, these do:

 "inoremap":[
        ["<A-i>", "k"],
        ["<A-j>", "h"],
        ["<A-k>", "j"],
        ["<A-l>", "l"],
    ],

And I found a bug using jupyterlab 3.0.8 and vimrc 0.5.2 on WSL2 Ubuntu 20.04 Anaconda(just use pip installed, do not install the node.js).
When I reopen the Jupyterlab, all the remapping will not work. And I add comments into vimrc(otherwise can not save change), and remapping will work again, but when i use jupyterlab for a while, and it will not work again. I need add a comment the vimrc again to make it run.

I'm not sure I totally follow the steps to reproduce this which makes it harder to debug. If you are able to come up with a minimal example demonstrating this that would be super helpful.

Also does refreshing the browser page help?

@ianhi
Copy link
Owner

ianhi commented Feb 23, 2021

I wonder if the issue when you re-open is due to the loading order of the jupyterlab-vim extension and this extension. I'm not sure if that's controllable with explicitly depending on the other extension though. I'd prefer not to do that as that would prevent this extension from working for the people who just want vim in the fileeditor

@yunlongYoung
Copy link
Author

yunlongYoung commented Feb 24, 2021

Hi, @ianhi

About Alt Key Mapping

This one worked for me perfectly.

{
"inoremap":[
        ["<A-i>", "k"],
        ["<A-j>", "h"],
        ["<A-k>", "j"],
        ["<A-l>", "l"],
    ],
"nnoremap": [
        ["h", "i"],
        ["j", "h"],
        ["k", "j"],
        ["i", "k"],
        ["H", "I"],
        ["J", "H"],
        ["K", "J"],
        ["I", "K"],
    ],
}

This one could not use <alt-key> to move, but normal mode ran well.

//just change all "A" to "a"
{
"inoremap":[
        ["<a-i>", "k"],
        ["<a-j>", "h"],
        ["<a-k>", "j"],
        ["<a-l>", "l"],
    ],
"nnoremap": [
        ["h", "i"],
        ["j", "h"],
        ["k", "j"],
        ["i", "k"],
        ["H", "I"],
        ["J", "H"],
        ["K", "J"],
        ["I", "K"],
    ],
}

Exit Cell Mode Cause Key Mapping Disorder

I found the problem occurred immediately when I leave the cell mode by shift-G(vim extension key) or mouse click to change cell.

//it has mapped in this way

//   i               ↑
//j  k  l         ↓  ↑ →

// as expected?
//❎  j, k
//✅  i, l
//✅  J, K, L, H, h
//❎  I

//The I key input at the line starth, which did not change its default behavior.
//The H key input at the line starth, which is as I expected.

It did not go all invalid, but partially invalid. And the invalid key mapped into vim default behavior.
I disabled all the Jupyter keyboard shortcuts, but problem came all the same.

Suggestion

  1. reinitialize the vimrc extension when each time enter a cell;
  2. put a full key list in README, for use <A-key> but not the <a-key>;
  3. add a correct example for this mapping;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants