One can take advantage of the text objects that are built in into Vim
(see :help text-objects). The desired edit can be stated as a
sequence of the following three actions.
-
Cut the text inside the square brackets:
di[ -
Select the (empty) square brackets:
va[Alternatively, you can just select the character under the
cursor and the one to the left of it, because the command
from step 1 always puts the cursor on the closing bracket:vh -
Paste the cut text over the selected brackets:
p
Altogether, it gives us the following sequence of Normal-mode commands:
di[va[p
or, when the alternative form of step 2 is used:
di[vhp