This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (78)
- # announcements (12)
- # babashka (2)
- # beginners (116)
- # calva (20)
- # cider (17)
- # clj-kondo (15)
- # cljs-dev (51)
- # clojure (32)
- # clojure-android (1)
- # clojure-dev (4)
- # clojure-europe (91)
- # clojure-gamedev (1)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-spec (12)
- # clojure-taiwan (1)
- # clojure-uk (10)
- # clojurescript (9)
- # conjure (3)
- # cryogen (4)
- # cursive (4)
- # data-science (1)
- # datomic (5)
- # depstar (5)
- # fulcro (39)
- # google-cloud (2)
- # kaocha (2)
- # malli (7)
- # off-topic (3)
- # pathom (3)
- # pedestal (5)
- # re-frame (19)
- # rewrite-clj (54)
- # ring (3)
- # shadow-cljs (12)
- # spacemacs (12)
- # specter (3)
- # tools-deps (63)
What's the best way to replace certain characters in a String with new lines?
I tried with the usual "vim-style" (https://stackoverflow.com/questions/71323/how-to-replace-a-character-by-a-newline-in-vim) replace but
\r just produces
^M in the source buffer.
E.g. I have a stacktrace as a single-line string and want to split it into multiple lines
a.clj: 25 b.clj: 58 b.clj: 365 d.clj: 51 java.lang.Exception: ... # should become: a.clj: 25 b.clj: 58 b.clj: 365 d.clj: 51 java.lang.Exception: ...
I wonder if iedit or multiple cursors would be useful for this... Will check when back at a computer
I ended up using
sed like this:
Still would be useful to know how to do it in emacs.
echo "a.clj: 25 b.clj: 58 b.clj: 365 d.clj: 51 java.lang.Exception: ..." | sed -E $'s/(: [0-9]+)/\1\\\n/g' | tee >(pbcopy)
SPC v v with as many v's needed to select the region
SPC n r to narrow to the region (so I can select spaces just from that region
v on one of the spaces to select the space character as a pattern
SPC s e to create iedit cursors on each space,
n to jump to the next cursor and
TAB to toggle the iedit cursor, removing every alternate cursor.
i for insert mode and
RET to create new lines
ESC to leave insert mode,
ESC to leave iedit mode
It sounds a lot, but its very quick to do if used to using iedit and narrowing.
I didn't quite get the thing with
TAB - couldn't make it work.
I can split it that way with simply replacing every space but there can be 3(?) spaces in each row (one of them is ommited from the example so there are only two)
I basically need to split on digits/regex, I think.
Multiple cursors is simpler
v to visually select the first space where you want to cut the line
C-n to place a cursor and jump to the next space
C-t to skip placing a cursor at that position and jump to the next space
C-t to skip a cursor at the space and
C-n to place a cursor at the place
RET when you have all the cursors needed
If there is a varing number of spaces, simply
C-t until you get to the place where a space should have a return charater and press
Oh and when finished,
g r q to kill all the cursors and go back to just one.
I did it with
SPC SPC replace-string, then the character i want to replace, then
C-q C-j as replacement. Most likely not the most elegant way, but did the trick.
I created a quick video as an example of using iedit and multiple cursors https://youtu.be/SCEQtSSb7Tc I shoud do more of these and join them up into a little demo of these really useful tools