12

In atom editor, when I type console.log( for example, it becomes console.log() and the cursor stays between the two parenthesis. So I have to use End button or Right arrow key to jump out of there. Is there any way to use Tab instead (to jump out of ending parenthesis/brackets/quotation) ?

Alireza Omidi
  • 163
  • 1
  • 2
  • 12
  • Would be nice to have it out-of-the-box. Take a look at [this thread](https://discuss.atom.io/t/move-cursor-out-of-parenthesis-quotes-or-brackets/10618) on Atom Discuss. – Pablo Bianchi Jul 27 '17 at 03:30

2 Answers2

18

If you just keep typing, then the closing ) will be 'swallowed' by Atom's bracket matcher, so you don't need to press End or .

However, there are some situations where Atom's bracket matcher doesn't swallow up keypresses and you can't just keep typing. For example, when you enter the following code, after pressing ; you might need to move the cursor past the closing curly brace (which Atom automatically inserted):

if (someCondition) {
    doSomething();
}

In situations like this, you can use a custom command and a custom keymap to jump the cursor forward. Here's how...


Go to the file menu and select 'Open Your Init Script', then paste the following code into the file. This defines a command that can move the cursor forward, jumping over a single bracket, brace, or quotation mark.

SymbolRegex = /\s*[(){}<>[\]/'"]/
atom.commands.add 'atom-text-editor', 'custom:jump-over-symbol': (event) ->
  editor = atom.workspace.getActiveTextEditor()
  cursorMoved = false
  for cursor in editor.getCursors()
    range = cursor.getCurrentWordBufferRange(wordRegex: SymbolRegex)
    unless range.isEmpty()
      cursor.setBufferPosition(range.end)
      cursorMoved = true
  event.abortKeyBinding() unless cursorMoved

You have to close and re-open Atom to reload the init script.

Next, go to the file menu, select 'Open Your Keymap', and enter a keybinding for the new command. You could use the TAB key, but that would conflict with Atom's default keymap for snippets, so here I have used Alt+) instead:

'atom-text-editor:not([mini])':
  'alt-)': 'custom:jump-over-symbol'

Another option is just to disable Atom's automatic insertion of closing brackets. I think you can do that by going to Settings → Packages → bracket-matcher → Settings, and clearing the option 'Autocomplete Brackets'.

crumbletown
  • 525
  • 1
  • 4
  • 12
  • Thanks - sounds super basic, but this was bugging me as well – ruby24 Jan 03 '16 at 22:24
  • 1
    I wonder what the point of auto-typing the closing bracket is then. If you type '(' and automatically get a ')' that you still have to type (and have swallowed), something seems a little pointless? – Jesse Mar 31 '16 at 22:04
  • 1
    This is one thing I really liked from Notepad++. Also, if alt-) is too awkward, I use Shift+Space as the key binding. – jinglesthula Apr 14 '16 at 21:43
  • 1
    It's worth noting that entering the shortcut more than once jumps to the position after subsequent 'closing' characters, which can be handy (like if you forgot semicolons several places) – jinglesthula Apr 14 '16 at 21:48
  • In case anyone else runs into this, the above code works, except recently it broke, but only for parens. All other characters in the regex work fine. I installed the package @JAC links in their answer and it works great (after adding in the characters I wanted in the package settings). Still mapping it to Shift-space though ;) – jinglesthula Dec 19 '17 at 18:12
10

I also wanted this in Atom so I went ahead and made a package for it. https://atom.io/packages/tab-through

Added value over crumbletown's solution is that you can change the keybinding (I personally prefer tab, hence the package name) and characters you want via package settings, vs. having to make edits to the init script.

JAC
  • 101
  • 1
  • 4