In the current buffer I have a list of file paths (one per line). I want set “args” to that file list.
How can I do this?
Try this series of commands:
ggVGJ"ayy:args then press ctrl-r, then a
ggVGJ will join all the lines into a single line.
"ayy will yank the new single line into register a.
:args (filenames) will set the arguments, and
Ctrl-r, a will drop the contents of register a into the command you are currently typing.
If you don’t want to mess up the current buffer (file you are editing), then yank all the lines into a blank temporary buffer first.
:execute "args ".join(map(getline(1, line('$')), 'fnameescape(v:val)'))<CR>
getline(1, line('$')) will return a list of lines in the current buffer (from the first (
1) to the last (
map(getline(1, line('$')), 'fnameescape(v:val)') will escape all filenames in case they contain spaces or other special characters,
join(...) will join the resulting list by inserting space between every two list items, then it will passed to an
args command by