12

I'm using spacemacs to edit Python code.

When I type an opening parentheses, the closing parentheses is automatically inserted for me and the cursor is put in the middle for further typing. But: once I am done typing inside the parentheses, I need a quick way of jumping out of them and landing after the closing parenthesis.

Right now, I switch to normal state, move the cursor one unit (when I'm on the character just before the closing parenthesis), and then re-enter insert state with a. How can I do this more efficiently?

  • (Don't use smartparens etc. in the first place? IOW, if it hurts, don't do it. Why limit yourself to "typing stuff inside the parentheses"? Emacs already lets you know which right paren corresponds to which left paren. There is no need to hamstring yourself by creating little cells to work in.) – Drew Aug 7 '15 at 13:57
  • 3
    Can't you just type a closing paren? If not, try C-M-n. – nanny Aug 7 '15 at 14:30
  • @nanny Thanks. I was not aware of it. – Aviral Goel Aug 8 '15 at 12:07
  • @Drew You are right. But smartparens provides a couple of nice features too, especially useful for scheme/racket programming. – Aviral Goel Aug 8 '15 at 12:09
9

In smartparens-mode, the function sp-up-sexp will move you out of a set of parentheses (bind to your key of choice):

Move forward out of one level of parentheses.

...

Examples:

(foo |(bar baz) quux blab) -> (foo (bar baz) quux blab)|

(foo (bar |baz) quux blab) -> (foo (bar baz) quux blab)| ;; 2

(foo bar |baz -> (foo bar baz)| ;; re-indent the expression ​ )

(foo |(bar baz) -> (foo)| (bar baz) ;; close unbalanced expr.

To reiterate a simple version of the docstring examples, with the following text and | as the cursor:

(hey, I'm| in the parentheses) and I'm outside them

M-x sp-up-sexp (or whatever you bind that function to for convenience) will take you to:

(hey, I'm in the parentheses)| and I'm outside them

Also note that, if the cursor is on the closing parenthesis, you can just type that parenthesis and smartparens will interpret it to mean "move past this parenthesis" rather than "insert another parenthesis."

3

Try up-list (which is a built-in Emacs function)

It lets me jump out of strings, parens, brackets with any nesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.