Reputation: 984
As the title.
Since _
is the movement to the first non-whitespace character in the line, and c + movement
generally means to change (aka delete + go into insert mode) the buffer from the cursor to the movement, why does this not work? It seems to delete the entire line, instead of from the cursor to the beginning of line (aka cc
or C
). Is there an alternative for this?
Upvotes: 2
Views: 73
Reputation: 121
Amadan's answer give's the reason why c_
doesn't work.
Answering the second part of your question
Is there an alternative for this?
Yes, there is. Use c^
!
Check out :help left-right-motions
and you'll find:
^ To the first non-blank character of the line.
exclusive motion.
Upvotes: 1
Reputation: 198324
Because _
is defined as an up/down motion. From :help up-down-motions
:
_ <underscore> [count] - 1 lines downward, on the first non-blank
character |linewise|.
It just defines the position where the cursor will end up once the up/down motion is finished. Thus, c_
operates on lines, just like cj
does.
Upvotes: 2
Reputation: 183
This is a known issue in vim. See https://github.com/vim/vim/issues/2189#issuecomment-334441965:
_
is a linewise movement (I guess because of VI compatibility). All commands (liked
orc
) that are combined with a linewise movement affect whole lines. You can make the movement (in combination with a command) characterwise by prefixing it withv
. Socv_
anddv_
should do what you want.
Upvotes: 5