11
votes

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) ?

2
Would be nice to have it out-of-the-box. Take a look at this thread on Atom Discuss.Pablo Bianchi

2 Answers

18
votes

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'.

10
votes

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.