I'm looking for a command to delete from the cursor to the first non-whitespace character on the same line. I've googled for a while and tried several possibilities. No joy. Does someone out there know how to do this?
One way to make sure to remove all trailing whitespace in a file is to set an autocmd in your . vimrc file. Every time the user issues a :w command, Vim will automatically remove all trailing whitespace before saving.
Immediately after opening a file, type “gg” to move the cursor to the first line of the file, assuming it is not already there. Then type dG to delete all the lines or text in it.
Position the cursor where you want to begin cutting. Press v (or upper case V if you want to cut whole lines). Move the cursor to the end of what you want to cut. Press d.
The sequence dw will delete all characters from the cursor until the next word. This means that if you execute the command while standing in the middle of a word, it will delete the remainder of that word and subsequent whitespaces. May or may not be what you're looking for.
You may want to try dW. This will move by "WORD" (see help for WORD and word), which looks more appropriate for your question.
The dw
won't meet your needs in, for example:
array[1] = 5
Hitting dw
while positioned in the a
will leave you with:
[1] = 5
But using dW
will result in:
= 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With