I typically use ddO
. dd
to delete the current line, and O
(that's a capital o) to add a new line.
This is also 3 keystrokes, but dd
counts only as 1 and a half, and I find O
easier to type than $
.
It's different from the 0D
solution in that it does auto-indentation, for example with this code (where !···
is a tab, and █ the cursor:
def asd():
!···if foo:
!···!···foo()█
!···!···foobar()
0D
will leave you with:
def asd():
!···if foo:
█
!···!···foobar()
And ddO
will leave you with:
def asd():
!···if foo:
!···!···█
!···!···foobar()
And if you press <Esc>
immediately after this, Vim should remove the auto-indentation, so you have the same as with 0D
.
There is no 'correct' way, it will depend what exactly you'll want to do. I prefer ddO
because it's more flexible, and because it's "in my fingers" :-)
:%s/\s*$//