Here's a situation I'm in every day:
0 .outer_selector {
1
2 .inner_selector {
3 margin: 0;
4 padding: 0;
5
6 input { display: none; }
7 }
8
9 }
Now I want to cut and paste the .inner_selector
somewhere else. How can I do it? I can't figure out any way to quickly delete the logical .inner_selector
block with it's surrounding whitespace; i.e., the equivalent to dap
but for this brace-delimited block. Here are various ideas, in increasing order of gnarliness. (ai
and ii
mappings are via the vim-indent-obj plugin.)
3Gdai
. This almost works but leaves the closing brace for the.inner_selector
block where it is.2Gdai
. No good; this deletes the whole.outer_selector
block.2Gdii
. This deletes the correct block, but not the surrounding whitespace (i.e., the equivalent ofdip
instead ofdap
).2Gf{d%
. Go to{
withf{
, delete to matching brace (d%
). This deletes the text from the brace on line 2 to its matching brace, but leaves the text ".inner_selector
".2Gf{v%okd
. Starts same as (4), then jump to top of selected text (o
), extend by one line upward (k
), and delete (d
). Same as (3), above.3Gvaikojjd
. Select text, select one additional line upward (k
), jump to bottom of selected region (o
), select two lines down (jj
), delete (d
). This works.
I can define a keyboard mapping for the last one and be done with it, but before I do that I want to be sure I'm not missing something here. Since it's such a common code construct in many languages, I'm surprised it's this difficult to treat text { /* multiple lines /* }
as a text object, or that there's no plugin for it.