zsh tab completion messes up command line formatting
Asked Answered
U

3

9

I'm running zsh with oh-my-zsh on OS X. Every time I use zsh's awesome tab-completion, formatting on the current command line prompt gets really screwed up. For example:

I'll be typing cd fo and try to tab-complete for the 'foo' directory; zsh prompts for completion but changes the command line to cd fo cd fo while it's waiting for me to complete. It's not a big deal but very annoying. Any suggestions?

Uhland answered 29/7, 2013 at 18:43 Comment(2)
Do you have color highlighting in the prompt? If you don't do those escape sequences in the proper way, the shell gets confused about how much space it takes and this messes up redrawing the command line when it does completion.Mentholated
See this answer or perhaps this question. If you'd like more help, posting the contents of your ~/.zshrc or other applicable files is probably needed.Alliterative
I
9

I had the same issue on PopOS and Arch linux. I tried a bunch of solutions from various places but the only solution that worked for me was this suggestion by romkatv on an issue on the oh-my-zsh github repository.

The solution is to make a copy of the .zsh-theme file of whatever theme you're using in oh-my-zsh and surround all non-ASCII characters (like emojis) with %{%G<CHARACTER>%}

For example, the default oh-my-zsh theme robbyrussel contains 2 non-ASCII characters. The '➜' character in the prompt

PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"

and the '✗' character in the prompt for git directories

ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"

Using %{%G<character>%} around the 2 non-ASCII characters like this

PROMPT="%(?:%{$fg_bold[green]%}%{%G➜%} :%{$fg_bold[red]%}%{%G➜%} )"

and this

ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}%{%G✗%}"

solved the issue for me.

Idell answered 2/10, 2019 at 7:12 Comment(0)
P
3

I have faced the same problem before, my solution was disabling some zsh plugins. The second probability is that your colour theme may contain a bug which causing this.

# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git)

This is the final version of my plugin section in the ~/.zshrc file. Any other plugin between parenthesis may be the reason of your situation.

If your problem still continues you need to post your ~/.zshrc to let us check what is in there.

Panicle answered 19/8, 2014 at 2:54 Comment(0)
S
3

I had the same issue. Interestingly, I saw the problem only iterm2 while the prompt is correctly displayed in the standard terminal of OS X (after reverse-i-search/tab-completion). The reason seems to be that iterm2 defaults to Unicode (UTF-8) default encoding, which however is not correctly interpreted if the corresponding language variable is not set in the shell.

Solution: add the following to your .zshrc

export LC_ALL=en_US.UTF-8

The prompts will be displayed correctly.

Schnell answered 22/11, 2022 at 11:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.