tags:

views:

40

answers:

2

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? Thanks.

A: 

Try this series of commands: ggVGJ"ayy:args then press ctrl-r, then a

Explanantion: 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.

Kimball Robinson
Fantastic response. I don't know the Ctrl-r commad to drop the contents of a register into the command line but for paths with spaces the other response run perfectly. Thanks.
kaptux
A: 
:execute "args ".join(map(getline(1, line('$')), 'fnameescape(v:val)'))<CR>

Explanation: getline(1, line('$')) will return a list of lines in the current buffer (from the first (1) to the last (line('$')) line, 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 execute.

ZyX
Great response. In fact I'm trying to learn a bit of "vim scripting" and this answer gives me many interesting concepts. Thanks a lot!
kaptux
In short you could use "getline(1, '$')" instead of "getline(1, line('$'))" (at least in gvim 7.3)
kaptux
@kaptux > In short you could use "getline(1, '$')" instead of "getline(1, line('$'))" (at least in gvim 7.3) /// I know about this but I constantly forget it since some other functions that accept line numbers does not accept line expressions: for example, try any `syn*` function. Using `line()` is safe in all cases.
ZyX