Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all arbitary spaces before a line in Vim

I'v written a plugin where it comes to parsing a XML tag. The content inside the tag is indented and when i copy the parsed string into the file it's gettting like:

    Example line
        This is part of the parsed line
        Thats goes one
    End of line

What I want is to remove all spaces in front of these lines, the final text should be

Example line
This is part of the parsed line
Thats goes one
End of line

I've tried to use = but it doesn't work the way I want. How can I do that with minimal key strokes ?

like image 891
Fatih Arslan Avatar asked Jan 07 '11 12:01

Fatih Arslan


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 a space in vi?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.

How do I remove spaces from a line in Unix?

The command gsub(/ /,"") removes blanks from those lines.


2 Answers

To format a line to the left I use :left. Use this format an entire file:

:%le 
like image 125
Peter Rincker Avatar answered Sep 19 '22 02:09

Peter Rincker


A simple search/replace s/^\s*// should do the trick, but it's probably not the minimal version.

like image 20
Lukáš Lalinský Avatar answered Sep 20 '22 02:09

Lukáš Lalinský