When I cut and paste in VIM by pressing v, and go to the end of the line using $, and press d, the next line gets moved up to the same line I’m cutting.
How do I stop this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It moves up because you have removed all the characters including line return/feed.
There are multiple solutions as usual with Vim. There is no “one true way” but you can try the following commands.
You can use
D(capital) in normal mode which will erase everything until the end of line.See
:help DUsing another motion
What you could do instead of using $ to move to the end of the line, use g_. It will move to the last non blank character of the line and won’t select line return.
See
:help g_So vg_d should work as you want.
Using Replace
Alternatively, what you could do instead of cutting, you could replace the erased character by a blank using the space character.
So v$rSPACE should work to erase but it will not save the replaced characters in register (for pasting later for example).