简体   繁体   中英

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM