getting the full path of arguments in command completion=file

9 views
Skip to first unread message

Martin Alaçam

unread,
Mar 22, 2020, 4:56:06 PM3/22/20
to vim...@googlegroups.com
Hello, 
 
command! -nargs=* -complete=file Loader call Test(<f-args>)

How would I get the <f-args> to be full paths to the arguments (file names)?
I am guessing it has to be done in the command, and not in the function being called (Test)? 

Thanks in advance, 

Martin 

Martin Alaçam

unread,
Mar 22, 2020, 6:10:25 PM3/22/20
to vim...@googlegroups.com
Found it: 
command! -nargs=* -complete=file Loader for f in [<f-args>] | call Test(fnamemodify(f, ":p")) | endfor

Gary Johnson

unread,
Mar 22, 2020, 6:15:18 PM3/22/20
to vim...@googlegroups.com
On 2020-03-22, Martin Alaçam wrote:

> command! -nargs=* -complete=file Loader call Test(<f-args>)
>
> How would I get the <f-args> to be full paths to the arguments (file names)?
> I am guessing it has to be done in the command, and not in the function being
> called (Test)? 

Here's one way to do it. Replace "echo path" by your actual
processing of each file.

function! Test(...)
for file in a:000
let path = fnamemodify(file, ":p")
echo path
endfor
endfunction

Regards,
Gary

Martin Alaçam

unread,
Mar 22, 2020, 6:19:45 PM3/22/20
to vim...@googlegroups.com
Ah, it works from within the function too, that is smart. And the nicer solution. Thanks! 

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200322221328.GA25471%40phoenix.
Reply all
Reply to author
Forward
0 new messages