Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

:vim.send-key command not working for some keys? #62

Open
kenny-evitt opened this issue Dec 3, 2015 · 4 comments
Open

:vim.send-key command not working for some keys? #62

kenny-evitt opened this issue Dec 3, 2015 · 4 comments

Comments

@kenny-evitt
Copy link

I'm trying to answer the following Stack Overflow question:

key bindings - Bind multiple actions to one key in lighttable - Stack Overflow

It seems like I should be able to add the following to my user.keymap file to implement this:

[:editor "esc" :auto-complete.remove (:vim.send-key "<Esc>")]

But it doesn't work.

Trying to isolate what's going on, I added the following to my user.keymap file instead:

[:editor "capslock" (:vim.send-key "<Esc>")]

But it doesn't work. Nor does ... (:vim.send-key "Esc").

But other argument values, like "$" or "0" do work. What's up with Escape?

@cldwalker
Copy link
Member

:vim.send-key has a different effect for me - all of the keys trigger normal mode keys regardless of whether I'm in insert or normal mode. For example, [:editor "esc" (:vim.send-key "j") (:vim.send-key "j")], moves my cursor down 2 lines. What do you see?
Given that send-key just calls handleKey, it's probably worth trying handleKey in a non LT context and asking on the codemirror mailing list if you want handleKey to trigger insert key behavior

@kenny-evitt kenny-evitt self-assigned this Dec 5, 2015
@cldwalker
Copy link
Member

Closing as I haven't heard back. Feel free to reopen if you have investigated this more

@kenny-evitt
Copy link
Author

The post "Changing a Vim editor to normal mode" on the CodeMirror Google Groups group is really really relevant ( 😄 ):

Matt Mower:

Given a reference to a CodeMirror instance using Vim-mode, can anyone tell me how to set it to normal mode?

The best I could come up with from looking at the code was to use handleKey(cm,"<Esc>") to emulate the user pressing Escape. If the editor is in normal mode sending handleKey(cm,"A") does correctly put it in append-at-end-of-line-mode. But neither sending (or C-[ or cribbed from vim.js) seems to work although my naive reading of the code for handleKey suggests that it should.

What I am trying to do is create a plugin for LightTable that returns any Vim editors to normal mode when the application loses focus. Using LT I am able to get a reference to the CodeMirror instance in any editor tab and send it messages.

Yunchi Luo:

There is no method in the API to do so. You could emulate a browser event on code mirror's hidden input field for the ESC key. Just google to see how to emulate a browser event.

Otherwise, you could send a patch to expose exitInsertMode() on vimApi so you can call CodeMirror.Vim.exitInsertMode(cm). It seems like a harmless enough change.

Chris Granger:

@mightguava, seems like we should be able to do this through handlekey, any idea why we can't?

Yunchi Luo:

You can't, handleKey only handles keys in normal mode and visual mode, not insert mode, not to mention that it's marked as a testing hook and should not be used externally.

Matt Mower:

Thanks Yunchi.

To get my plugin working asap I went the event route and, modulo a lot of fiddling to figure out how to JS stuff without jQuery, that works just fine.

@kenny-evitt kenny-evitt reopened this Feb 1, 2016
@kenny-evitt
Copy link
Author

Please un-assign me.

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

No branches or pull requests

2 participants