Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write each line of the result of a a system() call into a list in Vimscript?

Tags:

vim

I'd like to loop over the files in a directory using Vimscript. Reading usr_41.txt and having searched around, the best I can come up with is something like let dir_contents = system('ls')

But since system() isn't returning a list, I can't loop over it. Is there either a way I can save the results of a system call as a list, or a Vim command or function that does so already?

like image 667
Thomas Avatar asked Jun 20 '11 12:06

Thomas


1 Answers

You can get a list with split(system('ls'), '\n'), which will give you a list of files providing you don't have files with newlines in them.

like image 77
richq Avatar answered Oct 26 '22 02:10

richq