18

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

nobe4
  • 16,033
  • 4
  • 48
  • 81
FelixJN
  • 283
  • 1
  • 2
  • 6
  • 2
    Also: :1,10s/\v^(\s|\d)*/ (remove any number of spaces or digits at the start of the first 10 lines) – VanLaser Aug 19 '15 at 13:18

1 Answers1

32

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
nobe4
  • 16,033
  • 4
  • 48
  • 81
  • 1
    sorry for explicitly asking: :normal will allow to execute the command as if I would enter it when navigating with the cursor? – FelixJN Aug 19 '15 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 – nobe4 Aug 19 '15 at 12:37
  • 2
    The colons in front of normal after the range are redundant. – FDinoff Aug 20 '15 at 01:24