質問

I'm using Vim to edit Clojure code and I'm giving paredit a go, as Emacsen generally talk about how good it is in Emacs, once you get the hang of it.

If I have an expression that passes a lambda to a function:

(wrapper-func (fn [] whatever))

And I want to change it so that all I'm left with is the inner lambda:

(fn [] whatever)

What's the right way to do that using paredit? I keep getting frustrated and going back to balancing parens by hand. I can generally get as far as deleting the 'wrapper-func' element in the list, finishing with:

((fn [] whatever))

But then it seems impossible to remove the outer or inner parens.

役に立ちましたか?

解決

From paredit's help:

<Leader>I      Raise the current symbol, i.e. replace the current list with
               the current symbol by deleting everything else (except the
               symbol) in the list, including the eclosing pair of parens.
               For example pressing <Leader>I at position marked with |:
                   (aaa (b|bb ccc) ddd)  --->    (aaa |bbb ddd)

So, place your cursor here

(wrapper-func (fn [] whatever))
              ^

and press <Leader>I.

See more at :help paredit.

他のヒント

Here is how to do it without paredit.vim:

Place your cursor here:

(wrapper-func (fn [] whatever))
              ^

Then type:

y% :to copy inner parent to clipboard,

v2a( :to select outer parent,

p to replace that outer parent by the clipboard.

Note1: v2a( can be replaced by hva( or vha( to get the cursor out of inner parent: a( is then selecting outer parent.

Note2: If you do not want to include the signs ( and ), use i( instead of a(.

Note3: If y% is replaced by d%, v2a( can be replaced by va( because outer parent became current parent. It is one keystrole less. but if your system crash while typing this you may lose the content of inner parent.

Or simply we can do this by keeping cursor at:

  (wrapper-func (fn [] whatever))
                ^

execute following key stroke

d{(%x

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top