Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Reasoning: I have autocd enabled, yet I never use it because it makes tab-completion a huge pain, as every single command name on my system will be completed along with the filename completions.

Desired behavior: I want zsh to ONLY tab-complete commands if the completed string is not a prefix of any of the files in the current folder.

Example of desired behavior:

$ ls
foo1
foo2
$f<TAB>
foo1
foo2
$fi<TAB>
find
... (other commands that start with fi)

I guess if this is not possible it would at least be nice to put directory completions before command completions.

share|improve this question

3 Answers 3

I have the following three lines in my ~/.zshrc file:

zle -C complete-files complete-word _generic
zstyle ':completion:complete-files:*' completer _files
bindkey "^F" complete-files

this binds Ctrl-f to file/folder completion, so if I know I definitely want to tab complete a filename then I use Ctrl-f instead of <tab>. Obviously you can use a different binding by changing ^F to something else. The result:

$ ls
  foo1
  foo2
$ f<tab>
  f2py
  factor
  faillog
  ...
$ f<Ctrl-f>
  foo1
  foo2
share|improve this answer
    
I was aware you can do this but this requires me to think what kind of tab completion I want before I tab-complete which is a big no-no for me. –  user223814 Jun 13 '13 at 1:40

To get this exact behavior put this to your .zshrc:

compdef '_autocd || _command_names' -command-

I found the answer in this thread.

share|improve this answer

On bash if you do

. f<TAB>

then only file names will be listed. I don't know if zsh have the same behaviour. In general, bash autocompletes using only file names when you must input a path.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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