2

v^ and v_ both select to the first non-blank character on the line.

d^ deletes to the first non-blank character on the line, but d_ deletes the entire line.

Why is this? Is there any reason to use it over dd?

5

_ is a linewise motion operator (:h linewise), its primary purpose is to move your cursor to <count> - 1 lines below your current position.

For example:
5_ will move your cursor 4 lines down

The motion to the beginning of the line is just a side effect of that move. So when you type d_, the delete operation is applied from the current line to 0 lines below the current line. Result is, the current line gets deleted.

^ is a characterwise motion operator (:h characterwise), that's why it doesn't delete the whole line.

In that case, since the visual mode doesn't change the text, you don't see the linewise / characterwise difference.

I don't think d_ has any difference with dd in terms of performances or behavior, you can use one or the other.

| improve this answer | |
  • 2
    _ is mostly there for operators that dont provide the “hit twice for a line”—handy in custom maps/operators – D. Ben Knoble Mar 11 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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