I often have long strings I want to break into new lines in various languages. E.g. in python

x = ("The quick brown fox jumps over the lazy dog")
                         /\ cursor here


x = ("The quick brown fox "
     "jumps over the lazy dog")

Or in javascript

var x = "The quick brown fox jumps over the lazy dog."
                            /\ cursor here


var x = "The quick brown fox " + 
        "jumps over the lazy dog."

Is there a way to do this in vanilla Emacs or Spacemacs?


The smartparens package provides the command sp-split-sexp. From the docs (for spacemacs)

sp-split-sexp is an interactive compiled Lisp function in ‘smartparens.el’.

It is bound to SPC j s, M-m j s.

(sp-split-sexp ARG)

Split the list or string the point is on into two.

If ARG is a raw prefix SPC u split all the sexps in current expression
in separate lists enclosed with delimiters of the current

See also setting ‘sp-split-sexp-always-split-as-string’ which
determines how sexps inside strings are treated and also for a
discussion of how to automatically add concatenation operators to
string splitting.


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

  "foo bar |baz quux"   -> "foo bar" |"baz quux"

  ([foo |bar baz] quux) -> ([foo] |[bar baz] quux)

  (foo bar| baz quux) -> (foo) (bar|) (baz) (quux) ;; SPC u

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.