20

For a file looking like this:

   2  AD,42.546245,1.601554,Andorra,376
   3  AE,23.424076,53.847818,United Arab Emirates,971
   4  AF,33.93911,67.709953,Afghanistan,93
   5  AG,17.060816,-61.796428,Antigua and Barbuda,1

I am trying to remove the leading spaces and numbers for the first 10 lines, so I'd end up with

AD,42.546245,1.601554,Andorra,376
AE,23.424076,53.847818,United Arab Emirates,971
AF,33.93911,67.709953,Afghanistan,93
AG,17.060816,-61.796428,Antigua and Barbuda,1

Why does "remove two words" :d2w work for a single line, but not for a range :1,10d2w?

NOTE:

The problem itself is solved due to the fixed format, using :1,10s/.\{8\}//, so this is more about understanding how to use ranges with :dNw

1
  • 2
    Also: :1,10s/\v^(\s|\d)*/ (remove any number of spaces or digits at the start of the first 10 lines) Commented Aug 19, 2015 at 13:18

1 Answer 1

34

You can do this with the normal command :

:1,10normal d2w

This is because the d operator doesn't accept a range, but only a motion :

:h d

["x]d{motion}           Delete text that {motion} moves over [into register x].

Alternatively you can select your text in visual mode and you can do :

:'<,'>normal d2w
3
  • 1
    sorry for explicitly asking: :normal will allow to execute the command as if I would enter it when navigating with the cursor? Commented Aug 19, 2015 at 12:35
  • 2
    :normal allows you to execute a command as it was entered in normal mode (when you navigate the cursor with hjkl). See : :h :normal Commented Aug 19, 2015 at 12:37
  • 2
    The colons in front of normal after the range are redundant. Commented Aug 20, 2015 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.