Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map a command to multiple edits

Tags:

vim

I'm using the plugin vim-surround, which maps ds( to "delete surrounding brackets", e.g. turns (Hello) into Hello. I want to map a command to delete a function appliction, e.g. turning foo(bar) into bar.

I tried

nmap <Leader>df bdt(ds(

to go to the beginning of the word, delete up to the first (, and then delete the surrounding parentheses. However, when I use it, it only deletes up to the bracket, and doesn't do the subsequent deletion of the brackets themselves. I've tried putting other editing commands after the initial part, and that works. So

nmap <Leader>df bdt(x

works as expected.

Similarly, I tried just doing

nmap <Leader>s ds(

and that also works!

Other things that don't work:

nmap <Leader>df bdt(<bar>ds(

Does anyone know how I can make this work?

like image 350
mpeytonjones Avatar asked Dec 10 '25 07:12

mpeytonjones


1 Answers

I would suggest a simpler mapping like the following.

nmap <silent> dsf ds)db

This will delete the "surrounding" function application so the cursor needs to be on or inside the parens.

like image 124
Peter Rincker Avatar answered Dec 13 '25 01:12

Peter Rincker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!