-
Notifications
You must be signed in to change notification settings - Fork 63
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
jj/jk to esc #74
Comments
I don't think the commands If it really matters to you I'd be okay with adding a hack in the meantime. |
Right, they are not exist, but can be configured and there is a recipe in its wiki. For VSCodeVim there is such setting as it is not possible to do outside these modal-editing plugins, so I suggest to have it there too. It's pretty common and it will be nice to have it there sometime. |
I do use jk in kakoune, and it would be great to have it in Dance as well |
I sort of thought about it and thought about several ways to add it to Dance, and then I realized that it's actually already possible. Spoiler: install macro-commander (or whatever else you prefer with that kind of feature), and add the following macro: "switchToNormal": [
{
"javascript": [
"const editor = vscode.window.activeTextEditor;",
"if (editor === undefined || editor.selection.active.character === 0) return;",
"const lastCh = new vscode.Range(editor.selection.active.translate(0, -1), editor.selection.active);",
"if (editor.document.getText(lastCh) !== 'j') return vscode.commands.executeCommand('default:type', { text: 'j' });",
"else return editor.edit((b) => b.delete(lastCh)).then(() => vscode.commands.executeCommand('dance.set.normal'));"
],
},
], Then in the keybindings, add: {
"key": "j",
"command": "macros.switchToNormal",
"when": "editorTextFocus && dance.mode == 'insert'",
}, What it does is that whenever you press
I might add support for macros to Dance to make things easier (and especially to no longer need to both define a macro and a keybinding -- a keybinding should be enough), but in the meantime this works. I also considered the following ideas:
|
With {
"key": "j",
"command": "dance.run",
"when": "editorTextFocus && dance.mode == 'insert'",
"args": {
"code": [
"const editor = vscode.window.activeTextEditor;",
"if (editor === undefined || editor.selection.active.character === 0) return;",
"const lastCh = new vscode.Range(editor.selection.active.translate(0, -1), editor.selection.active);",
"if (editor.document.getText(lastCh) !== 'j') return vscode.commands.executeCommand('default:type', { text: 'j' });",
"else return editor.edit((b) => b.delete(lastCh)).then(() => vscode.commands.executeCommand('dance.set.normal'));",
],
},
}, |
This solution for v0.4.0 seems to work quite well, thanks! |
The solution posted didn't work so well with multi selections, leaving behind j's, but this
seems to do the trick. I wish I could pop out the undo stack for the typed |
In most situations a next character of {
"key": "j j",
"command": "dance.set.normal",
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j a",
"command": "type",
"args": {"text": "ja"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j e",
"command": "type",
"args": {"text": "je"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j i",
"command": "type",
"args": {"text": "ji"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j o",
"command": "type",
"args": {"text": "jo"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j p",
"command": "type",
"args": {"text": "jp"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j q",
"command": "type",
"args": {"text": "jq"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j r",
"command": "type",
"args": {"text": "jr"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j s",
"command": "type",
"args": {"text": "js"},
"when": "editorTextFocus && dance.mode == 'insert'"
},
{
"key": "j u",
"command": "type",
"args": {"text": "ju"},
"when": "editorTextFocus && dance.mode == 'insert'"
}, Not smart, but it is simple. |
Since this seems like a popular feature, the next version of Dance will be able to do this natively. The {
"key": "j",
"command": "dance.openMenu",
"args": {
"menu": {
"items": {
"j": {
"text": "escape to Normal",
"command": "dance.modes.set.normal",
},
},
},
"prefix": "j",
},
"when": "editorTextFocus && dance.mode == 'insert'"
} |
I'm attempting to map
But I'm getting an error ( |
@sransara This issue is actually #177 (comment) (tl;dr: |
Hi, thank you for this great extension!
Are there anyting for handling
jj
orjk
to get out of insert mode? Or how hard it is to implement?The text was updated successfully, but these errors were encountered: