Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

arpeggio key combinations? (for 'jk' smash escape) #221

Closed

Description

@docwhat

I use Arpeggio to implement a reliable 'jk' smash escape: Arpeggio inoremap jk <Esc>

I tried the usual:

inoremap jk <esc>
inoremap kj <esc>

...but I kept running across variables/words that had jk and kj in them which would totally kill my concentration (and randomly change things 😀 ).

I have to use a smash escape because the escape key on my mac book pro was causing me massive wrist pains.

Activity

  1. drbraden commented on May 8, 2014

    @drbraden

    I always remap "jj" to escape and it works really well. Super easy to type and I don't remember ever having to type a literal "jj". Not the same as chords like Arpeggio enables, but I find it very useful.

    This is how I did it in Atom's keymap file:

    '.vim-mode.insert-mode:not(.mini)':
      'j j': 'vim-mode:activate-command-mode'
    

    I only enabled it for insert mode so it won't interfere with "j" as a movement key.

  2. darkseas commented on May 9, 2014

    @darkseas

    @drbraden How do you type a normal 'j' in insert mode?

    Using the keymapping you have suggested, if i type jump I get ump, and of course a 'jj' escapes to command mode.
    I prefer a 'kj' mapping which means I can use a 'kk' for a single 'k' in Atom, but this will get old very quickly.
    So how can we avoid throwing away the first letter of the command?
    Is this likely to be a small task or delving into Atom internals?

  3. drbraden commented on May 9, 2014

    @drbraden

    Oh, oops, you're right. I guess I just haven't had to type a j in insert mode since I made the change. It works fine in vim and sublime.

    It looks like there is an "operator-pending" mode that might be used to get this functionality without discarding the first key when subsequent keys don't match a mapping. It's in the master branch, but it's not in the current release, yet.

    In master, they use operator-pending mode to implement "d i w" while in command mode, so I played around a bit trying to do something similar, but so far I haven't been able to get it to work.

  4. nathansobo commented on May 9, 2014

    @nathansobo
    Contributor

    I've created atom/atom-keymap#16 to track the integration of textinput events with multi-keystroke bindings. Fixing that still won't allow for multi-key chords, but at least provides better support for the typical j k escape bindings.

    I've also created atom/atom-keymap#17 to track support for chords, which is more sophisticated. In time, this is all reasonable, but I personally won't be able to get to it until our plans for the editor renderer are more stable.

  5. drbraden commented on Jun 26, 2015

    @drbraden

    Here is a currently working method (as of v1.0.0) of exiting insert mode with "jj" (or the more common "jk" with a minor edit to the keymap.cson change):

    #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-command-mode')
    
    #keymap.cson
    'atom-text-editor.vim-mode.insert-mode':
      'j': 'exit-insert-mode-if-proceeded-by-j'

    Credit for this goes to @rdlugosz for his comment at #334 (comment)

  6. oh-its-jimjam commented on Jun 29, 2015

    @oh-its-jimjam

    @drbraden Thanks for the code snippet! I wanted to map 'jj' to escape in Atom and you've saved me a lot of time 👍

  7. drbraden commented on Jun 30, 2015

    @drbraden

    @lambdaburrito Glad to hear it! I've spent way too much time chasing down a solution for this, or finding a new one after a breaking upgrade, so I was hoping I could save others the time 😄

  8. AriaMinaei commented on Jul 4, 2015

    @AriaMinaei

    Thanks @drbraden! Here is a one-line modification of your code snippet, using editor.buffer.undo() instead of editor.backspace() to preserve selections:

    #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.buffer.undo()
        atom.commands.dispatch(e.currentTarget, 'vim-mode:activate-command-mode')
    
    #keymap.cson
    'atom-text-editor.vim-mode.insert-mode':
      'j': 'exit-insert-mode-if-proceeded-by-j'
  9. AriaMinaei commented on Jul 5, 2015

    @AriaMinaei

    Looks like editor.buffer.undo() undoes keystrokes in batch, so, ignore my last comment :)

  10. maxbrunsfeld commented on Jul 24, 2015

    @maxbrunsfeld
    Contributor

    We've fixed this bug. In the next Atom release (v1.0.3), you'll just have to do this:

    'atom-text-editor.vim-mode.insert-mode':
      'j j': 'vim-mode:activate-normal-mode'
  11. SurenderLohia commented on Aug 4, 2015

    @SurenderLohia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions