1

In vim, is it possible to delete the first N characters in each line in a paragraph without using visual mode or using dot command multiple times?

Convert

www.some_website.com
www.some_webiste2.com

to

some_website.com
some_webiste2.com

Without using visual mode or d4l j .?

I guess my question can be also phrased as "is there a linewise operator for a paragraph text object?"

2
  • 1
    Vim's substitute command? Example: :%s/^....// to remove the first four characters of each line.
    – sjnarv
    Jun 24, 2015 at 16:27
  • Why do you need to avoid visual mode? The obvious method is using visual block mode to delete all of that stuff in a single command.
    – Ben
    Jul 2, 2015 at 3:06

2 Answers 2

3

Executing a substitution on a range of lines is probably the most "Vim-like" solution.

Assuming you want to work on what Vim considers a paragraph:

:'{,'}s/^www\.

If you like counting characters:

:'{,'}s/.\{4}

One could use :normaltoo:

:'{,'}norm! 4x

See :help navigation, :help :normal, :help \{.

0

In addition to the substitute and directly using normal command mentioned on another answer, you could also repeat a normal command (as d4l) in any number of lines using the :global command:

:g/^www/normal d4l

Explanation:

  • :g/<patter>/ - execute on any line that matches <pattern> - . will match all non-empty lines, ^www\. would match only those starting with urls
  • normal d4l - execute d4l in normal mode

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .