Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jump over end parenthesis/bracket/quotation in atom editor with TAB

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

like image 626
Alireza Omidi Avatar asked May 16 '15 10:05

Alireza Omidi


People also ask

How to move cursor out of bracket?

Space is just a space, and Cmd+Space moves the cursor to the end of the text on that line. Thanks so much!

How do you undo something in an atom?

When in a file that needs reverting, press ctrl-cmd-r to revert the file.


2 Answers

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

like image 154
crumbletown Avatar answered Sep 18 '22 18:09

crumbletown


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.

like image 43
JAC Avatar answered Sep 16 '22 18:09

JAC