When using paredit how do you wrap braces around text? I've used paredit several times however I get frustrated because it stops me from doing what I want.
Example:
(foo
(bar 1 2 3)
baz 1 2 3)
Opps, baz 1 2 3
should be wrapped like so:
(foo
(bar 1 2 3)
(baz 1 2 3))
But, no... :
(foo
(bar 1 2 3)
() baz 1 2 3)
You didn't mention what editor you're working in. In any case if you just enter an opening paren then its closing pair is immediately added as well. In order to wrap an expression in parentheses you need to use a 'wrap' function.
In emacs this can be paredit-wrap-round
or M-(
, please find an emacs paredit cheatsheet here.
In vim using slimv this is ,W
(if you select an expression first then the whole expression will be wrapped).
If you happen to wrap the wrong number of elements then you can move them into/out of the s-expression (see 'slurp' and 'barf' for emacs), or you can move the parenthesis (,<
or ,>
for vim).
Type C-u (
instead of (
to make it wrap around everything from the point on, or M-3 (
(or M-3 M-(
) to make it wrap around the next three S-expressions.
Alternatively, you can mark the region you want to parenthesize and then type (
.
Another alternative is to type (
and then hit M-)
to slurp in what you want term by term.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With