Skip to content

Instantly share code, notes, and snippets.

@drbraden
Last active August 29, 2015 14:25
Show Gist options
  • Save drbraden/d4a3a1caf09429d0b842 to your computer and use it in GitHub Desktop.
Save drbraden/d4a3a1caf09429d0b842 to your computer and use it in GitHub Desktop.
Allow "jj" to exit insert mode in Atom (working as of 1.0.2)
# Slightly modified version created by rdlugosz at https://github.com/atom/vim-mode/issues/334#issuecomment-85603175
#keymap.cson
'atom-text-editor.vim-mode.insert-mode':
'j': 'exit-insert-mode-if-preceded-by-j'
#init.coffee
atom.commands.add 'atom-text-editor', 'exit-insert-mode-if-preceded-by-j': (e) ->
editor = @getModel()
pos = editor.getCursorBufferPosition()
range = [pos.traverse([0,-1]), pos]
lastChar = editor.getTextInBufferRange(range)
if lastChar != "j"
e.abortKeyBinding()
else
editor.backspace()
atom.commands.dispatch(e.currentTarget, 'vim-mode:activate-command-mode')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment