Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete till non-whitespace in vim?

Tags:

vim

whitespace

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?

like image 532
Singlestone Avatar asked Aug 07 '11 20:08

Singlestone


People also ask

How do I delete unwanted spaces in Vim?

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.

How do I delete all words in Vim?

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.

How do I clear up in Vim?

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.


2 Answers

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.

like image 130
richardolsson Avatar answered Oct 06 '22 23:10

richardolsson


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 
like image 39
sidyll Avatar answered Oct 07 '22 01:10

sidyll