Quickest way to change a pair of parenthesis to brackets in vim
I personally use https://github.com/tpope/vim-surround as it provides everything I could ever need, reading through the source you can see the solution is non-trivial.
A typical example:
Hello("World")
with the cursor somewhere between the ()
, you can type cs([ in normal mode to get:
Hello["World"]
surround.vim
is easily installed with either Pathogen or Vundle, personally I prefer vundle. https://github.com/VundleVim/Vundle.vim
adding the important commented point:
cs([ adds spaces in the block, this should be cs)]
I would simply do it like this: %r]^or[
.
Here's an explanation:
f(
-- put cursor on first parenthesis you want to change (if it's not already there).%
-- jump to the matching parenthesis.r]
-- replace the parenthesis with a bracket.CTRL-O
-- jump back to to first parenthesis.r[
-- replace the parenthesis with a bracket.