Using VIM to code in Python I often have to change or delete the parameters of functions.
I expected to find a command like ci, to select the text between two commas. Somehow like selecting between matching parentheses or brackets with ci" and ci(.
def function1(a,b,delete_me, c):
pass
def function2(a,b,delete_me):
pass
def function3(a,b,delete_me=[1,2,3]):
pass
How can I achieve the expected result efficient with VIM giving the cursor points to the desired parameter already?
Parameter matching is difficult (especially with constructs like nested function calls and arrays) as it depends on the underlying syntax. That's why there's no built-in inner / outer parameter text object.
I use the argtextobj.vim plugin, which works fairly well.
I don't think there's a builtin command for this but here are some examples which might help.
Selecting text:
ve -- end of word boundary
vE -- end of line
Deleting:
de -- delete until end of word
dE -- delete until end of line
Some regex magic could also do the work, if you have to remove a bunch of identical things.
:%s/\,d.*\]//g -- Replace anything with that begins with ,d and ends in ] with ""
def function3(a,b,delete_me=[1,2,3]):
pass
Turns into
def function3(a,b):
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With