1

I have the following lines in my vimrc:

command -nargs=1 Compare call Compare(<f-args>)
function Compare(file)
    execute "vnew " . a:file
    setlocal nomodifiable
    wincmd h
endfunction

It immutably opens a given file in a new window strictly for reference. This works perfectly for me (though I am open to suggestions to improve it).

What I'd like to add is the ability to Tab autocomplete files, like with other commands that take files like :e or :vnew. All that does right now is type ^I (I have nocompatible set, so that's not an issue).

I've done some looking around, but I haven't found a way that would work with just Tab. cmdline-completion, wildchar, and wildmode don't seem to have the answer I'm looking for.

Is there a way to tell Vim that the command should expect a file or otherwise enable Tab completion here?

1 Answer 1

2

Sure, see :help -complete and try

command -nargs=1 -complete=file Compare call Compare(<f-args>)
1
  • 2
    I knew it would be something simple, but I just couldn't find it. Thank you very much!
    – Elenian
    Jan 26 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.