h5k7eq
Last Updated: February 25, 2016
·
440
· lwheng
6d831aa3db1c5e6bfd5df50535258e42

Vim shortcut to remove brackets

Let's say in your source code you have something like:

1  let timesTwo = (2*)
2  let myList = map (timesTwo) [1,2,3]

Now, your compiler (or lint) might tell you that the round brackets in Line 2 is redundant (in this case it is!)

You wish to remove the brackets and you might use a combination of the d, x or w command in vim, or even go into INSERT mode and use backspace.

Here's my tip, add the following line to your .vimrc:

nmap <C-9> di(va(p

What that line does is that it maps the keyboard shortcut Ctrl+9 to execute the following di(va(p.

Now, go back to your source code and place your cursor on the ( in Line 2. Type Ctrl+9 and see the magic happen.

Further reading

  1. You can modify the mapping to another key combination.
  2. You change the ( to [ or { for different kinds of brackets
  3. You can break down the di(va(p command into di(, va( and p and explore what they do.

Thanks for reading!

Say Thanks
Respond

2 Responses
Add your response

17875
450fe761a3072080abe31ce2ce3ac62b

There is a plugin vim-surround could make it easier.

over 1 year ago ·
25002
2f66c42d644cabb3394caf024748fe98

+1 for vim-surround

over 1 year ago ·
Filed Under