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

Vim noremap seems to have no effect #6386

Closed
kanreki opened this issue Aug 18, 2020 · 6 comments
Closed

Vim noremap seems to have no effect #6386

kanreki opened this issue Aug 18, 2020 · 6 comments
Labels

Comments

@kanreki
Copy link

kanreki commented Aug 18, 2020

I tried mapping 'jk' to <Esc> in insert mode, using the noremap() method; but it didn't seem to have any effect. (The 'jk' trick is a popular substitution for exiting insert mode: example.)

If I instead use the map() method it does work, but I'm in the habit of using "non-recursive" mapping whenever possible, as suggested here.

I wrote a jsbin to demonstrate it: https://jsbin.com/higabaj/edit

I was using Chrome version 85.0.4183.59 on a Chromebook. And CodeMirror version 5.56.0.

@marijnh marijnh added the vim label Aug 19, 2020
@benhormann
Copy link
Contributor

benhormann commented Aug 22, 2020

CodeMirror.Vim.mapCommand('jk', 'action', 'exitInsertMode', {}, { context: 'insert' });

If you also want to use jk to get out of visual mode, do the same using exitVisualMode.

Explanation: <Esc> has special handling, it isn't in the key map. (noremap here is not exactly like in Vim). If you noremap to <C-[> or <C-c> instead, it would actually add it to the key map (actually that wouldn't work because they are keyToKey type mappings and that type is excluded, along with ex mappings).

@JianqiaoLu
Copy link

please try this:
CodeMirror.Vim.map("jk", "", "insert");

@kanreki
Copy link
Author

kanreki commented Jan 28, 2021

That didn't work for me. Did you try it on the jsbin demo that I mentioned?

@kanreki
Copy link
Author

kanreki commented Jan 28, 2021 via email

@benhormann
Copy link
Contributor

@tjlujianqiao The markdown formatter allows HTML tags so you need to encode the < symbol as &lt;. Or simply surround code with ` (backticks / grave accent).

I can confirm :imap jk <Esc> works.


Here noremap is effectively a shorthand for mapCommand; it copies a mapped command. So for keys that are not mapped to a command (e.g. <Esc>), it does nothing. It should throw an error upon failure, would be more helpful.

@kanreki
Copy link
Author

kanreki commented Oct 7, 2021

Thank you, @benhormann.

My evil twin previously claimed that the CodeMirror.Vim.mapCommand() call that you suggested did not work. However, I see that it actually does work (not sure what was going wrong before).

Also, :imap jk <Esc> as well.

@kanreki kanreki closed this as completed Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants