views:

51

answers:

1

I have in my .vimrc:

let g:PROJECT1="/a/b/c"
let g:PROJECT2="/d/e/f"

I then do a bunch of operations on the above strings:

let str=":!/usr/bin/ctags ".g:FLAGS_CPP." -f ".g:TAG_FILE." ".g:PROJECT1
exec(str)
let str=":!/usr/bin/ctags ".g:FLAGS_CPP." -f ".g:TAG_FILE." ".g:PROJECT2
exec(str)

I want to replace the above code with a for loop that iterates on an array of strings. How would you get an array of strings in my .vimrc?

What would the for loop syntax be for iterating over the array of strings?

+2  A: 

Use lists let mylist = [1, two, 3, "four"]


for var in mylist
    operations
endfor

See the vim help page on lists and this wiki page on loops.

Pierre-Antoine LaFayette