Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete in zsh (with oh-my-zsh) not working #353

Open
nunoh opened this issue Feb 18, 2015 · 26 comments
Open

Autocomplete in zsh (with oh-my-zsh) not working #353

nunoh opened this issue Feb 18, 2015 · 26 comments

Comments

@nunoh
Copy link

nunoh commented Feb 18, 2015

Sorry, if I am missing something obvious, but hopefully you might be able to tell me what that is.

I have installed autojump with brew in my setup of zsh (version 5.0.7) and oh-my-zsh but don't seem to be able to use tab autocompletion, instead I am just getting the files and folders of the current dir.

I've added the [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh line to my .zshrc and also tried enabling the autojump plugin that comes with oh-my-zsh (should I?). In any case, I wasn't able to get the tab completion working. Everything else works ok.

What am I missing? Thanks!

@jutkko
Copy link

jutkko commented Feb 22, 2015

For me as well. TABbing in autojump is not doing anything...

@politicus
Copy link

Tabbing in autojump is stil not doing anything.

@cloudyan
Copy link

+1,I am just getting the files and folders of the current dir too. why ??? I installed autojump with brew ,but it's not working

@cloudyan
Copy link

In mac, it's not working; but in ubuntu it's OK

@anrao91
Copy link

anrao91 commented Feb 3, 2016

My fix for this issue is -

  1. Execute the zshrc in the bash first, and then change the SHELL, say -
    $~/.zshrc
    $ZSH
    #Provided you have followed the installation steps given here - https://github.com/robbyrussell/oh-my-zsh/blob/master/README.markdown

P.S : It worked in mac for me

@chenglou
Copy link

chenglou commented Feb 3, 2016

FWIW, I'm on Mac too (with zsh). Had this problem a while ago, but it's been fixed for a while for me.

@kud
Copy link

kud commented Dec 5, 2018

I've got the same problem:

image

@boyoungzheng
Copy link

Same here. Any updates?

@boyoungzheng
Copy link

With oh-my-zsh, the autojump completion works.
Without oh-my-zsh, the completion does not work.

I installed autojump through homebrew. I made sure
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
is in my ~/.zshrc

autojump v22.5.3
zsh 5.7.1 (x86_64-apple-darwin19.0)

@boyoungzheng
Copy link

I think I've found the solution while reading Moving to zsh
Without on-my-zsh, I need to run
autoload -Uz compinit && compinit
I also found a similar command in ~/.oh-my-zsh/oh-my-zsh.sh
autoload -U compaudit compinit
I guess the key thing is the compinit.

(If my solution also works for you, please give me a thumb up. 😃)

@victor-h-b
Copy link

@boyoungzheng your solution worked for me, except it's adding annoying double underscore ("__") after the typed text:

so:
$ j tmp<tab><tab>

turns into:

$ j tmp__

tmp__1__/bla/tmp-something
tmp__2__/bla/another-tmp
...

there are also few identical suggestions, which seem like a bug.
but good enough for me :)

@MauritsDescamps
Copy link

MauritsDescamps commented Jun 7, 2020

@boyoungzheng your solution worked for me, except it's adding annoying double underscore ("__") after the typed text:

so:
$ j tmp<tab><tab>

turns into:

$ j tmp__

tmp__1__/bla/tmp-something
tmp__2__/bla/another-tmp
...

there are also few identical suggestions, which seem like a bug.
but good enough for me :)

Did you manage to fix this? I'm having the same problem. Autocomplete works but it just shows two underscores.

@victor-h-b
Copy link

@MauritsDescamps no, I haven't managed to solve it.

@shaungrady
Copy link

Anyone find a fix for this yet? I'm stuck with Maurits' issue also.

@shaungrady
Copy link

Well apparently it's it's a feature:

ZSH tab completion fixed.

ZSH behavior now matches Bash behavior. However it requires the compinit module to be loaded. Add the following line to ~/.zshrc:

autoload -U compinit; compinit

To use type:

j

A menu showing the top database entries will be displayed. Type in any number followed by to complete the entry.

@rkulla
Copy link

rkulla commented Nov 1, 2020

@shaungrady Interesting. Ok I ran that and got some initial warnings about insecure directories. That was easy to resolve by running compaudit and fixing the permissions those the directories listed.

The markup in that file isn't right so I had to read the RAW form of the README to see what it was saying. It said to type j followed by space followed by 2 tabs and the enter the number you want to jump to but that just pops up two underscores for me. However, I can do j xTABTAB to expand to x__1_foo x__2_bar and enter 2 to jump to bar.

If this is the best it functions that's fine, but something still seems a little off to me. Thanks.

@mesaglio
Copy link

Hi, i add de plugin autojump un .zshrc file, and works.
MacOS Catalina V10.15.7
autojump v22.5.3

plugins=(git autojump)

@mesaglio
Copy link

mesaglio commented Dec 1, 2020

Hi, i add de plugin autojump un .zshrc file, and works.
MacOS Catalina V10.15.7
autojump v22.5.3

plugins=(git autojump)

And move the source $ZSH/oh-my-zsh.sh line from .zshrc at the end of the same file.

@rkulla
Copy link

rkulla commented Dec 1, 2020

I really think @shaungrady has solved this issue by saying to add autoload -U compinit; compinit to get completion to work. (man zshcontrib). The plugins=(autojump) thing is only necessary if you use oh-my-zsh but that plugin is just a script (autojump.plugin.zsh) that sources the autojump profile script.

If you don't use oh-my-zsh, like I don't, you still have to source the script (which will be in a different location depending on what OS and/or how you installed it, e.g., for me on MacOS installing autojump with Homebrew, it's in /usr/local/etc/profile.d/autojump.sh).

In summary, the steps whether you use oh-my-zsh or regular zsh are:

  1. In .zshrc, source the autojump profile script (or if using oh-my-zsh just have plugins=(autojump) source it for you.
  2. In .zshrc, make completion work by adding autoload -U compinit; compinit -y
  3. Start completing things by typing j foo[tab][tab] and when the menu pops up, enter the directory number and enter.

@jeremyfix
Copy link

@rkulla I did experience the same issue on Ubuntu 18.04, oh-my-zsh .

I did add the autoload -U compinit; compinit -y in my zshrc as suggested and I got the tab completion working now ! Thank you !

@emacdona
Copy link

I'm not going to pretend to know anything about compinit, but some experimentation has shown that running it clobbers any auto completion that has already been configured. This coupled with tons of recommendations on the web to run it to "fix" autocompletion issues appears to have led to multiple projects including it in their auto completion initialization files (two that I use: nvm and sdkman appear to have done so) -- which results in the latest one to load clobbering the configuration of all those before it!

So, here's what I put in my .zshrc to "fix" it. Seems to be working well enough so far... not sure what issue I may run into in the future:

autoload -Uz compinit
compinit -u

# It seems that countless recommendations on the web to run:
# autoload -Uz compinit && compinit

# Have resulted in everyone's zsh autocomplete initialization running that. I have no idea
# what it does, however experimentation has shown that running "compinit" clobbers any
# completions you already had configured. Which totally sucks if you configure auto completion
# for multiple tools in your zshrc
alias compinit="echo no more compinit!"

@adrienafl
Copy link

adrienafl commented Apr 1, 2022

Fixed it by adding this to .zshrc (Apple M1)

  if type brew &>/dev/null; then
	  FPATH=$(brew --prefix)/share/zsh-completions:$(brew --prefix)/share/zsh/site-functions:$FPATH

    autoload -Uz compinit
    compinit
  fi

@shaohuahuang
Copy link

shaohuahuang commented Jun 6, 2022

@shaungrady MauritsDescamps
Is the two underscore issue resolved? I encounter the same issuerecently

I tried to add below line into my .zshrc file, it does not resolve the issue.
autoload -U compinit; compinit

@shaungrady
Copy link

@shaohuahuang It's a feature:

Example:

$ j tmp__

tmp__1__/bla/tmp-something
tmp__2__/bla/another-tmp

You press 1 to jump to the first option, or 2 to jump to the second option.

@cloudyan
Copy link

cloudyan commented Sep 1, 2022

In mac, it's not working; but in ubuntu it's OK

I now use z instead of autojump

image

@Hanlen
Copy link

Hanlen commented Oct 14, 2022

make sure that your code source xxx/xxx/autojump.sh is before the code source $ZSH/oh-my-zsh.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests