0

Let's say with the cursor I'm on b in

def f(a=1,
      b=2,
      c=3,
      e=4
      )

and we want to delete the whole argument including the line break, so that we get

def f(a=1,
      c=3,
      e=4
      )

but without deleting the preceding character (i.e. it should also be applicable to deleting a...) What is the shortest way to do so?

I'm asking because in non-vim texteditors you could do so by selecting the whole line using shift+down arrow and then deleting the selection using del, and so far I have not found an efficient way to do so in vim, the best I could come up with is using visual mode: v, j, h, d


You can also imagine a similar situation with something like

y = a * xa + \
    b * xb + \
    c * xc 
1
  • 2
    If you're writing a lot of python, I suggest setting up black+ale and letting it autoformat on save. It saves me the trouble of doing it manually; I would just press D on the a character and then save.
    – D. Ben Knoble
    Feb 27, 2020 at 16:45

2 Answers 2

5

You could do, DJx

D -> delete rest of the line
J -> join the next line
x -> delete the space added by join
1
  • Just a note that on the other lines, you don't need x
    – D. Ben Knoble
    Feb 27, 2020 at 16:44
2

the best I could come up with is using visual mode: v, j, h, d

h is needed, because you've set selection=inclusive (this is default). To make the selection behave like in a majority of other text editors use set selection=exclusive.

Next, if you want shift+arrow to start the selection you should set keymodel=startsel.

Also, "delete" normally works the same way as x, so having set the two options above you should be able to do "shift+down+delete" to do the job.

So, as you see, the whole difference is due to the "unusual" default settings.

2
  • Thanks for your answer, but I don't see how you can use these commands for my purpose: In each case the whole line (including the preceding characters) is deleted. I am however looking to delete everything from b to the character before c in this example - is that possible with these commands?
    – flawr
    Feb 27, 2020 at 15:53
  • @flawr If you want to make "shift+down+del" work then set selection=exclusive and set keymodel=startsel
    – Matt
    Feb 27, 2020 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.