Let Vim insert mode escape (esc) to normal mode even if suggestion dropdown open

Use case or problem

When typing a tag name or a file link in vim insert mode, obsidian will offer a dropdown of suggestions. If you want to go back to normal mode, you have to remember to hit escape twice if the suggestion dropdown is open while you are typing.

Proposed solution

Hitting escape while the suggestion dropdown is open only closes the suggestion box but I think it should put you in normal mode regardless of whether the suggestion dropdown is open. It’s annoying to think you’re in normal mode and try to do something only to realize you’re still in insert mode.

Current workaround (optional)

I attempted to use the vimrc plugin to imap <Esc> <Esc><Esc> but this doesn’t seem to work for me. Other workaround suggestions are welcome.

16 Likes

I’m also facing this issue. It really takes the flow out of vim.
It should be a simple fix. Hopefully, it’ll be addressed.

1 Like

Would really love to see this fixed as well.

1 Like

I have the same issue and it is pretty distractive.

1 Like

Related to: https://forum.obsidian.md/t/support-shift-esc-for-closing-autocompletion-popup/46176

1 Like

Would love to see a solution to this! The autocomplete popup completely destroys my flow whenever it shows up :slightly_frowning_face:

1 Like

Another +1 for getting this fixed!

Totally agreed here!

How do I disable the auto suggestions, this is very annoying? This also happens for the autosuggestions on words meaning that every word I am basically having to double click esc to exit insert mode.

This bug really bothers me, enough so that I’ve switched to editing my Obsidian markdown in neovim + obsidian.nvim, and only use Obsidian for minor edits and to view my vault.

I’d rather be able to use Obsidian for edits, so I’ve done some digging. It looks like the escape hardcode is here, in the CodeMirror autocomplete source. This specific keymap is read-only, but it appears the client can specify multiple keymaps, e.g. from ResourcesCo (I was unable to find other open source examples.)

I believe Obsidian should be able to:

  • provide hotkeys that override this keymap
  • create a custom keymap using these hotkeys that overrides the completionKeymap, and set it at a higher priority

I believe I can’t verify in Obsidian without either access to Obsidian source or decompiling the binary.

2 Likes

Thanks for digging. I hope the devs try further

1 Like

Ok, I’ve decompiled the obsidian.asar file via these instructions, essentially using npx asar extract obsidian.asar ob.unpacked

I made the file readable via js-beautify (js-beautify lib/codemirror/vim.js)

The header says

// vim.js based on https://github.com/codemirror/CodeMirror/commit/793c9e65e09ec7fba3f4f5aaf366b3d36e1a709e (2021-12-04)

// Modified from https://github.com/nightwing/cm6-vim-mode-experiment/blob/master/src/vim.js 103a9b5 2021-12-03

I went to the first link, and it looks like the escape key behavior is hardcoded in codemirror5.

Per the CodeMirror 5 readme,

NOTE: CodeMirror 6 exists, and is more mobile-friendly, more accessible, better designed, and much more actively maintained.

My above link/comment about the keymaps refers to CodeMirror 6.
I’m going to guess the best fix would be to upgrade to CodeMirror 6. Now the question is, is there something that is currently preventing that upgrade other than lack of time?

3 Likes

Per Credits - Obsidian Help and Goodbye legacy editor - Obsidian, we have already moved to CM6. It looks like vim.js may be lagging behind; I’m guessing updating this file would be welcome.

I might be wrong, there is a defaultKeymap in the file, even if it hardcodes esc.

I did find this resolved issue that links to ways to override the behavior of esc. I’ll poke at this as I have time.

3 Likes