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

Map 'Esc' to 'Ctrl-[' or 'jk' #115

Open
Yohanna opened this issue Jul 25, 2016 · 24 comments
Open

Map 'Esc' to 'Ctrl-[' or 'jk' #115

Yohanna opened this issue Jul 25, 2016 · 24 comments

Comments

@Yohanna
Copy link

Yohanna commented Jul 25, 2016

Is it possible to map the Esc key to Ctrl-[ or jk keys?

@mugukamil
Copy link

@Yohanna put in your keybinding.json file this line
{ "key": "j k", "command": "amVim.escape" }

@Yohanna
Copy link
Author

Yohanna commented Aug 7, 2016

Thanks but unfortunately this prevents the j key from moving the cursor downwards since now VSCode expects a second key to be pressed after j.

@mugukamil
Copy link

@Yohanna try this one https://marketplace.visualstudio.com/items?itemName=vscodevim.vim

scroll to the bottom

@Yohanna
Copy link
Author

Yohanna commented Aug 7, 2016

This only works with the Vim extension, it doesn't work with amVim 😞

@Liyw979
Copy link

Liyw979 commented Aug 15, 2016

hey,you can try my keymap
{
"key": "j k",
"command": "amVim.escape"
},{
"key": "j",
"command": "amVim.down",
"when": "editorTextFocus && amVim.mode != 'INSERT'"
}

@Yohanna
Copy link
Author

Yohanna commented Aug 15, 2016

Thanks a lot @liyiwei979621500 ! that did it.

@wjljack
Copy link

wjljack commented Aug 16, 2016

can't input j in insert mode...

@Yohanna
Copy link
Author

Yohanna commented Aug 16, 2016

@wjljack you're right, I didn't notice this when I tried it earlier.

@wjljack
Copy link

wjljack commented Aug 16, 2016

need a better solution...

@aioutecism
Copy link
Owner

aioutecism commented Aug 16, 2016

Custom keybindings are not supported now.
Something like this should be supported in the future:

settings.json:
{
    "amVim.customKeybindings": [
        {
            "key": "j k",
            "command": "escape",
            "modes": "Normal|Visual|VisualLine"
        }
    ]
}

@davetorbeck
Copy link

Any update on this one? Is it possible to map custom keys soon?

@aioutecism
Copy link
Owner

@davetorbeck
Sorry, haven't got time to do this. Please wait a little longer.
Pull Request is also very welcome!

@gnapse
Copy link

gnapse commented May 24, 2018

I assume custom key mapping limitations would also affect remapping "j" as "gj", and "k" as "gk", right?

@aioutecism
Copy link
Owner

@gnapse
Yes.

Besides, gj, gk are difficult(maybe impossible) to be fully implemented using the current VSCode APIs.
Moving cursor won't be a problem, but things like dgj won't work as expected.

@gnapse
Copy link

gnapse commented May 25, 2018

I have gj and gk working with another vim extension for vscode: https://github.com/VSCodeVim/Vim

This is the extra config needed in the settings:

    "vim.otherModesKeyBindingsNonRecursive": [
        {
            "before": [
                "k"
            ],
            "after": [
                "g",
                "k"
            ]
        },
        {
            "before": [
                "j"
            ],
            "after": [
                "g",
                "j"
            ]
        }
    ],

I tried to switch to amVim, because it gets at least one thing right that that other extension does not, but it does not support doing this, and also dap did not work for me for deleting an entire paragraph.

@aioutecism
Copy link
Owner

@gnapse
Yes, VSCodeVim is recording start and stop position of the cursor when executing VSCode's internal cursorMove command. This is much different than what amVim is doing.

I'll find a way to fully implement screen line/character movement. You cloud subscribe to #116 if you are interested.

About dap, word/sentence/paragraph TextObject support is missing right now. Please subscribe to #13 for updates.

Thank you for your feedback!

@austenc
Copy link
Contributor

austenc commented Aug 1, 2018

@aioutecism How could I help with this? Could you give me an idea or rundown of where to look and how it might work? I'm happy to take a stab at building a PR for it!

@aioutecism
Copy link
Owner

@austenc
Thank you for your interest in this!

I haven't think thoroughly, here is the idea that came into my mind.

We create a custom mapping option like this:

// settings.json:
{
    "amVim.customKeybindings": [
        {
            "from": "j k",
            "to": "escape",
            "modes": "Normal|Visual|VisualLine",
            "recursive": false,
        },
        // ...
    ]
}

Then, inside GenericMapper.match (https://github.com/aioutecism/amVim-for-VSCode/blob/master/src/Mappers/Generic.ts#L64), we transform the inputs: string[] using our customKeybindings setting and use the new one in rest of the method.

We may want to parse the customKeybindings setting in advance to split it by Mode and flatten all recursive maps so that everything runs fast inside match.

To understand the current implementation, you can start from here:
https://github.com/aioutecism/amVim-for-VSCode/blob/master/src/Dispatcher.ts#L35-L37

Please feel free to ask if you have any questions.

@austenc
Copy link
Contributor

austenc commented Aug 2, 2018

@aioutecism thanks for the response and direction!

I was curious how the other vim plugin handled this and found this issue: 74th/vscode-vim#42. Would providing a similar config value for imap / esc key combination work? Looking at that config option it seems much simpler for the end user, although what you proposed would be more flexible for other use cases.

@aioutecism
Copy link
Owner

@austenc
The implementation is ok but I don't think we should do the same thing for these reasons:

  • We are creating a temporary setting that will be deprecated in the near future.
  • It only works in Insert mode.
  • I don't think we need a lot more code to make a better implementation that supports a much wider situation.

However, please let me know what you think. 😄

@austenc
Copy link
Contributor

austenc commented Mar 6, 2019

Love the idea of a more flexible setting, and am finally diving in to this to see if I can contribute.
Your guidance was very helpful in gaining an initial understanding of the package structure and functionality, so thanks again for that! Unfortunately though, I am stuck already.

Could you perhaps explain how the Generic.match function handles multiple character inputs? When trying something like jj it seems to only receive single characters, so I'm not sure about how to proceed with coding the "transform inputs with the customKeybindings setting" part.

I put a print statement in match() to check what inputs are sent in, typed jj, and got this:
image

The work I've done so far (barely anything!) is here: master...austenc:custom-keybindings

@aioutecism
Copy link
Owner

@austenc

Currently, amVim creates a tree structure where each node represents one input from keyboard.

E.g. In Normal mode, j is a leaf node under the tree root, so when user press j on the keyboard, amVim found the leaf node(j) and do whatever bound to the node (moving all cursors down once).

Another case, command such as diw located on the tree like this: d -> i -> w. So when user press d, amVim found a node with children (i -> w) and waits for more input. After user press i and w, amVim finally found the leaf and does the corresponding command (delete inside word).

Thus, jj becomes very tricky because we already have j as a leaf node. My initial thought is to create an extra logic to allow a node being both leaf and non-leaf. Then, when this unique type of node (let's call it "Half") is matched by the inputs, we wait a second to see if more inputs will come. If more inputs came, we match down to children nodes, if not, we execute the command bound on the leaf part of the Half-node.

@austenc
Copy link
Contributor

austenc commented Mar 8, 2019

Wow! Thank you for such a detailed description of how the plugin works and how you are thinking about the solution! This is very helpful! However.... I think some of these changes may be a bit over my head and are probably best left to you @aioutecism.

Honestly, I've adapted to a capslock-as-escape-and-control setup on all my keyboards, so I don't find myself using jj any longer anyway. If you'd like some help testing the feature in the future, please let me know!

@MichaelGitArt
Copy link

There isn't posibility to change "esc" to another key comination yet? It's great plugin, but without "jk" key binding it's useless

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

No branches or pull requests

9 participants