On Tue, 6 Jun 2006, Charles E Campbell Jr wrote:

Salman Mohsin wrote:

I have a long list of city names (more than 2,000 of them) in a file, each
name on a separate line. I'd like to modify each line so that:

ABERFOYLE
.
.
ZURICH

Becomes:

cities[0] = "ABERFOYLE"
.
.
cities[2039] = "ZURICH"

Is there a way I could issue a command (or some commands) and achieve the
above?


The way I'd do it is to use a simple substitute and visincr.vim:

:[range]s/^.*$/cities[0]= "&"
(goto the first 0 in the first cities[0] line, enter visual-block mode) ctrl-v
(goto the last 0 in the last cities[0] line) :I

Visincr.vim will transform the visual-block column of zeros into an incremented
list.  You can get visincr.vim from:

http://vim.sourceforge.net/scripts/script.php?script_id=670

or the most up-to-date one from

http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs (see "Visual Incrementing").

visincr.vim also supports date, dayname, monthname, and alphameric incrementing.

Chip,

Visincr pads trailing spaces as the number of characters needed to
represent the end number increases. What I mean is, for the above
example, we will be left with:

  cities[0   ] = ...
  .
  .
  cities[2039] = ...

Could it be made to pad nothing? Or, in addition, even leading
zeros/spaces/other characters?

Also, are there plans for incrementing/decrementing hex & octal?

--
Gerald

Reply via email to