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

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Igor Forca
Hi,

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
j
dtc
j
dts
j
dti
j
dtm

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. would be much simpler to think and edit.
Thanks

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Ricardo Silva
Hi,

On 9/19/18 3:53 PM, Igor Forca wrote:

> Hi,
>
> 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
> j
> dtc
> j
> dts
> j
> dti
> j
> dtm
>
> 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.

Try "dw".

>
> 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. would be much simpler to think and edit.

Check "gq" (:help gq).

> Thanks
>

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Claus Atzenbeck
In reply to this post by Igor Forca
On Wed, 19 Sep 2018 at 7:53am -0700, Igor Forca wrote:

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. would be much simpler to think and edit.

I probably would mark the paragraph in visual mode, then use

 :s/^ *//

which I find easy to remember and quick to type. (No need for "\s\+" which is just more to type compared to " *".)

You also could mark the paragraph and do a few left shifts via

 <.....

"<" would shift the marked paragraph to the left; each dot would repeat this. Continue pressing "." until all lines have reached column 1.

Maybe this helps.

Best,
Claus

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Tim Chase
In reply to this post by Igor Forca
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Tim Chase
In reply to this post by Claus Atzenbeck
On 2018-09-19 17:36, Claus Atzenbeck wrote:

> 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. would be much simpler to think and edit.
> >
> I probably would mark the paragraph in visual mode, then use
>
>  :s/^ *//
>
> which I find easy to remember and quick to type. (No need for
> "\s\+" which is just more to type compared to " *".)

If you're looking for additional laziness, if you don't have any
flags (you don't in this case), you can drop the last "/", and if
you're *also* replacing with nothing (i.e., deleting the match), you
can drop the separator "/" too, making it just

  :s/^ *

If the file has a mix of tabs & spaces, you can

  :s/^\s*

-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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Igor Forca
Now reading Recardo's post (second post in thread) and playing around I have found there is:
diw
j.
j.
j.
j.

Which is exactly what I was looking for. No need for count (ed command), or no need for selecting for video.

Despite my preference all other ideas are excellent and I will use them this or some other times.

Thanks a lot for ideas and tips.
Regards

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Igor Forca
In reply to this post by Tim Chase
Now reading Recardo's post (second post in thread) and playing around I have found there is:
diw
j.
j.
j.
j.

Which is exactly what I was looking for. No need for count in (command mode), or no need for selecting (visual mode). I somehow prefer using normal mode, it is quicker and easier to partial undo.

Despite my preference all other ideas are excellent and I will use them this or some other times.

Thanks a lot for ideas and tips.
Regards

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Grant Taylor-2
In reply to this post by Igor Forca
On 09/19/2018 08:53 AM, Igor Forca wrote:
> I know there is ed command: 1,5s/^\s\+// but this is difficult to type
> quickly and requires a lot of thinking.

I don't know about difficult to type.  I type things like that quite
frequently.

As for (a lot of) thinking, well, I find that most of vim's power
requires some thinking.

Unless I had a reason not to, I'd likely use %s/^\s\+// and apply it to
the entire buffer.

> Using some normal command and repeating j. would be much simpler to
> think and edit.

I find that repeating commands gets tedious quite quickly.  Especially
if you're munging data.  Hence why I like regular expressions like the
one above, or macros (possibly of the recursive variety).  Why should I
have to mentally execute the test to see if I need to apply the action
to the line when I can have the computer do it for me.  I just need to
tell the computer what to do.

IMHO regular expressions and and macros lend themselves to more
automation.  It might even be possible to move the regular expression to
a (s)ed script.



--
Grant. . . .
unix || die

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Eli the Bearded
In reply to this post by Igor Forca
Igor Forca wrote:
> Now reading Recardo's post (second post in thread) and playing around I have found there is:
> diw
> j.
> j.
> j.
> j.
>
> Which is exactly what I was looking for. No need for count (ed command), or no need for selecting for video.

"diw"? That's some vim-ism, isn't it? Replace "diw" with "d^" and it
works in any version of vi you can find. As a motion command, "^" goes
to the first non-whitespace character on the line (forward or backward,
natch so "0d^" may be a better starting command). Also "d^" is a no-op
when run at the beginning of the line with no leading whitespace, but
"diw" appears to delete the first word in that case.

Elijah

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Michael Henry-5
In reply to this post by Tim Chase
On 09/19/2018 11:36 AM, Tim Chase wrote:

> 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.

> 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

Adding to Tim's suggestion: if you are going to change the
indentation on the entire paragraph, then ``vip`` is an easy way
to select the lines of interest without counting; then typing
``:%le`` will automatically use the visual range because Vim
will insert the line range ``'<,'>`` for you.

Tim continued:
> 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'

Similarly, you can ``vip`` followed by ``99<`` to use this
second method on a paragraph.

I find that text objects such as ``ip`` (inner paragraph) come
in handy very often, saving me from trying to count lines or
from starting visual selection mode and moving down a line at a
time or whatever.  It's another tool in the toolbox that I use
frequently.  ``:help text-objects`` for more details.

Michael Henry

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Tim Chase
On 2018-09-20 20:07, Michael Henry wrote:

> On 09/19/2018 11:36 AM, Tim Chase wrote:
> > or the visual selection
> >
> > :'<,'>le  
>
> Adding to Tim's suggestion: if you are going to change the
> indentation on the entire paragraph, then ``vip`` is an easy way
> to select the lines of interest without counting; then typing
> ``:%le`` will automatically use the visual range because Vim
> will insert the line range ``'<,'>`` for you.

Just a tweak:  If you're using visual mode, you don't want to type
the "%", just the ":le".

-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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Michael Henry-5
On 09/20/2018 09:32 PM, Tim Chase wrote:

> On 2018-09-20 20:07, Michael Henry wrote:
>> On 09/19/2018 11:36 AM, Tim Chase wrote:
>>> or the visual selection
>>>
>>> :'<,'>le
>>
>> Adding to Tim's suggestion: if you are going to change the
>> indentation on the entire paragraph, then ``vip`` is an easy way
>> to select the lines of interest without counting; then typing
>> ``:%le`` will automatically use the visual range because Vim
>> will insert the line range ``'<,'>`` for you.
>
> Just a tweak: If you're using visual mode, you don't want to type
> the "%", just the ":le".

Oops - quite right, thanks for the correction :-)

Michael Henry

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.