Skip to content

Instantly share code, notes, and snippets.

@bangedorrunt
Last active August 29, 2015 14:20
Show Gist options
  • Save bangedorrunt/ada61d690942ffaf345a to your computer and use it in GitHub Desktop.
Save bangedorrunt/ada61d690942ffaf345a to your computer and use it in GitHub Desktop.
Custom Binding Key Map for Atom Editor
#
init.coffee
atom.commands.add 'atom-text-editor', 'exit-insert-mode-if-proceeded-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-normal-mode')
atom.commands.add 'atom-text-editor', 'exit-insert-mode-if-proceeded-by-o': (e) ->
atom.commands.dispatch(e.currentTarget, 'vim-mode:insert-below-with-newline')
atom.commands.dispatch(e.currentTarget, 'vim-mode:activate-mormal-mode')
atom.commands.add 'atom-text-editor', 'exit-insert-mode-if-proceeded-by-shift-o': (e) ->
atom.commands.dispatch(e.currentTarget, 'vim-mode:insert-above-with-newline')
atom.commands.dispatch(e.currentTarget, 'vim-mode:activate-normal-mode')
# keymap.cson
'atom-text-editor.vim-mode.insert-mode':
'k': 'exit-insert-mode-if-proceeded-by-j'
'atom-text-editor.vim-mode.command-mode':
'shift-O': 'exit-insert-mode-if-proceeded-by-shift-o'
'o': 'exit-insert-mode-if-proceeded-by-o'
# keymap.cson
# Work with Atom +1.05
'atom-text-editor.vim-mode.insert-mode':
'j j': 'vim-mode:activate-normal-mode'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment