Delete whitespace for a set of lines in Vim editor

text processingvim

I have some text like the following in a file:

  sample text
    some random text
            even more random text
text with no indent
 worst indention

I need to delete the empty space before each of the lines.
For one line what I do is
0dw

I can repeat the same command using . but by manually navigating to the next lines.

But is there a way to apply '0dw' to those block of lines?

I suppose there is a way using macros, but I haven't used them before. But I am willing to learn them if ther is no other choice.

Best Answer

:%s/^\s\+
" Same thing (:le = :left = left-align given range):
:%le

Learn more here at http://vim.wikia.com/wiki/Remove_unwanted_spaces

If you want to do this for a particular range of lines:

:19,25s/^\s\+//

BTW, best way to start learning vim is to execute vimtutor command, it will teach you how to use Vim in Vim editor.

Related Question