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.
Regards,
Chip Campbell