aioutecism / amVim-for-VSCode

The Vim mode for Visual Studio Code(vscode) that works as expected.
https://marketplace.visualstudio.com/items/auiworks.amvim
455 stars 42 forks source link

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

Open Yohanna opened 8 years ago

Yohanna commented 8 years ago

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

mugukamil commented 8 years ago

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

Yohanna commented 8 years ago

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 commented 8 years ago

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

scroll to the bottom

Yohanna commented 8 years ago

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

Liyw979 commented 8 years ago

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

Yohanna commented 8 years ago

Thanks a lot @liyiwei979621500 ! that did it.

wjljack commented 8 years ago

can't input j in insert mode...

Yohanna commented 8 years ago

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

wjljack commented 8 years ago

need a better solution...

aioutecism commented 8 years ago

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 commented 6 years ago

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

aioutecism commented 6 years ago

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

gnapse commented 6 years ago

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

aioutecism commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@aioutecism thanks for the response and direction!

I was curious how the other vim plugin handled this and found this issue: https://github.com/74th/vscode-vim/issues/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 commented 6 years ago

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

However, please let me know what you think. 😄

austenc commented 5 years ago

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: https://github.com/aioutecism/amVim-for-VSCode/compare/master...austenc:custom-keybindings

aioutecism commented 5 years ago

@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 commented 5 years ago

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 commented 4 years ago

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