Escaping atom vim mode with kj
I’ve recently been trying out Atom and it’s vim mode. One of the first issues that I ran into was quick escaping from insert mode with ‘kj’ (otherwise known as ‘Smash Escaping’). Unfortunately naively trying to remap ‘kj’ to return to command mode blocks the event and breaks the ‘k’ key.
To get smash escape working you’ll need to update your
keymap.cson files like so:
#keymap.cson '.editor.vim-mode.insert-mode': 'j': 'exit-insert-mode-if-proceeded-by-k'
#init.coffee atom.commands.add 'atom-text-editor', 'exit-insert-mode-if-proceeded-by-k': (e) -> editor = @getModel() pos = editor.getCursorBufferPosition() range = [pos.traverse([0,-1]), pos] lastChar = editor.getTextInBufferRange(range) if lastChar != "k" e.abortKeyBinding() else editor.backspace() atom.commands.dispatch(e.currentTarget, 'vim-mode:activate-command-mode')
You’ll have to restart atom for this change to take effect. But once you do you should now be able to smash escape again. While this change is specific to ‘kj’, changing the key combo should be straightforward.
Big thanks to all of the people working through these issues on the vim-mode repo!