Nishant
Nishant

Reputation: 21934

How to get tab completion for a user defined command in Vim?

I am writing a small function that takes directory as argument .

function! GetDirectoryAndDoSomething(default)
         :let directory = input('Directory: ', a:default)
         "Call Some Function
endfunction

This works fairly well if I call GetDirectoryAndDoSomething('.') , however as it is a string input , there is no Tab Completion for directories . How can I actually get the tab compleition working for directory as a user input ?

Upvotes: 1

Views: 374

Answers (1)

Zach
Zach

Reputation: 4792

You probably want -complete=dir for your command.

Example:

command -nargs=+ -complete=dir Blah :echo "<args>"

This will echo whatever the user puts as an argument to Blah but more importantly it will tab complete any part of the the argument to be directories.

To find out more read :h :command-completion

Upvotes: 2

Related Questions