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
- You can modify the mapping to another key combination.
- You change the
(
to[
or{
for different kinds of brackets- You can break down the
di(va(p
command intodi(
,va(
andp
and explore what they do.
Thanks for reading!
Written by Heng Low Wee
Related protips
2 Responses
There is a plugin vim-surround could make it easier.
over 1 year ago
·
+1 for vim-surround
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#