Wednesday, September 19, 2018

Re: What is the quickes way to delete spaces in front of each line?

On 2018-09-19 07:53, Igor Forca wrote:
> I lot of times I have text something like:
>
> Sample:
> ----Lorem ipsum dolor sit amet,
> --consectetur adipiscing elit,
> --------sed do eiusmod tempor
> ---incididunt ut labore et dolore
> ---magna aliqua.
>
> Note: Characters "-" symbolizes spaces.
>
> I need to delete spaces in as quicker way as possible.
>
> Now I do it with command "delete to character" and move down cursor
> like: dtL
>
> Is there a quicker way?
>
> What would be nice is to have "some command" and then just use j.
> to move cursor down and repeat the command.
>
> P.S. I know there is ed command: 1,5s/^\s\+// but this is difficult
> to type quickly and requires a lot of thinking. Using some normal
> command and repeating j.

If you don't have to manually select which lines should be de-dented,
you can also use

:%le

which uses the :left command to remove all leading space. It works
with any range

:10,20le

or the visual selection

:'<,'>le

or with matching lines:

:g/pattern/le

You can read more at

:help :left

(there's also a ":center" and a ":right" that use the 'textwidth'
setting if you want those)

Alternatively, you can select a range with visual mode and use the
"<" command with a ridiculously large prefix-count like "99<" to
dedent the selected rows by 99 levels of 'shiftwidth'

:help <

Hope these help,

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: