I can do :echo globpath('~/path/to/dir', 'string*')
to get a list like:
/home/alec/path/to/dir/string_xyz123.mkd
/home/alec/path/to/dir/string_xyz456.mkd
/home/alec/path/to/dir/string_xyz789.mkd
but now I want to loop through that and for each /home/alec/path/to/dir/string_xyz123.mkd
that gets returned I want to substitute
on them.
Doing...
let fileList = globpath('~/Documents/wiki/subdir', 'string*')
for fileName in fileList
substitute(fileName, '/home/alec/Documents/wiki/subdir', 'newtext', '')
endfor
...produces error "List required"
:help for
and :help while
haven't been much help.
How do I iterate through this list of files?
substitute
, do you mean a:%s/oldtext/newtext/
command? If that's the case, you need to open the files into buffers... Please edit the question to clarify exactly what you want to do with the files (or the file names.)~
in vim may not work as expected for certain use cases. You may need toexpand()
it. (Or use$HOME
or the full typed out path.)List required
and I think @Matt's answer addressed that. Editing the question to make it about the next thing blocking you is not great (particularly once an answer addresses that)... Would you please edit it back to make about that (exclusively)? Then post a new question about the actual problem you're trying to solve. Thanks!