44

I'm using oh-my-zsh in Arch linux with the robbyrussell theme loaded. When I try to tab complete I end up with remnant characters appended to the prompt. If I delete the auto-completed characters, the remnant characters do not delete.

For example, if I type in:

~ /etc

then tab, it turns to

~ /e/etc/

with a list of options below. Even if I delete /etc/, the /e remains and I'm stuck with:

~ /e

I can't delete the /e. I have to execute a command to get rid of the remnant character.

Any idea what is going on here?

  • Without further information, it's probably a missing character or two in your prompt. Read [this question](http://stackoverflow.com/questions/7957435/zsh-auto-complete-screws-up-command-name/10644062#10644062), for example. Are you using the latest oh-my-zsh? Have you modified the prompt at all? Can I download oh-my-zsh from GitHub to test, and have an accurate representation of your setup? :) – simont Oct 11 '13 at 02:07

6 Answers6

87

It seems I had issues with locale configuration and non UTF8 configuration

In my case the fix was:

export LC_ALL="en_US.UTF-8"

and keep it permanent adding the line to .zshrc:

echo "export LC_ALL=en_US.UTF-8" >> .zshrc

More info in Ubuntu doc https://help.ubuntu.com/community/Locale

m3o
  • 3,881
  • 3
  • 35
  • 56
corbacho
  • 8,762
  • 1
  • 26
  • 23
  • 1
    Uncommenting the following line in the default `.zshrc` also seemed to do the trick for me: `export LANG=en_US.UTF-8` – skube Mar 12 '17 at 12:37
  • In Manjaro I need to change file `/etc/locale.conf` and `/etc/locale.gen` to add `en_US.UTF-8` configuration and run `locale-gen`. This fix my problem: https://wiki.archlinux.org/index.php/Locale_(Espa%C3%B1ol) – Victor Feb 11 '21 at 15:54
  • For whoever is on iOS and is using Starship like me, I had duplicated/remnant characters as well with tab completion. Adding this to my zshrc fixed it. – b0nes Mar 14 '22 at 10:02
32

As suggested by simont it is likely that the prompt you are using is using unprintable characters (like color escape codes) but does not indicate that those characters are unprintable. So when the prompt is redrawn the terminal believes that the prompt is wider than it actually is.

You indicate that a character sequence in the zsh prompt has zero width using the %{ and %} delimiters. For example my prompt is:

%{%(?.%F{green}.%F{red})%}➜%{%f%}

The (?...) is a ternary which sets the color of the prompt and it has been marked up to indicate that it is zero width. In the same way the %f resets the color and that has also been marked up.

You can test changes to your prompt by updating the PS1 variable, so you can try out different arrangements and see what works for you.

You can mark any characters in this way, so be careful about making your prompt too short!

Matthew Franglen
  • 4,441
  • 22
  • 32
  • 2
    This is the answer that actually solved the problem. I looked into my customized zsh theme and found this exact problem (`$fg[red]` instead of `%{$fg[red]%}`). I added the delimiters and now it works as expected. Thank you Matthew! – michalvalasek Jan 11 '19 at 09:12
  • Live saver! (check out my answer below to see how you can easily apply this technique) – user3196006 Jul 29 '23 at 08:29
9

I had the same problem, so on my quest for a solution I have encountered this article: https://wiki.archlinux.org/index.php/Locale

And, as it was suggested, to enable some locale system-wide, you just need uncomment the desired locale on /etc/locale.gen, for example, in my case:

en_US.UTF-8 UTF-8

After saving the changes on the file, execute (as root) on command line:

locale-gen

Reboot, and it works! (at least for me)

Paulo Oliveira
  • 2,411
  • 1
  • 31
  • 47
1

I had a similar issue, though not with oh-my-zsh but promptline; for me the solution was to remove from my configuration:

ZLE_PROMPT_INDENT=0
OJFord
  • 10,522
  • 8
  • 64
  • 98
1

I had a similar issue, with the theme tjkirch_mod though. Whenever I was working in a dirty git repo and used tab completion, the first character of the line was duplicated. Changing the character that indicates the git repo state solved the problem for me. Changed

ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}⚡"

to

ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}x"

esrehmki
  • 177
  • 1
  • 7
  • I added `export ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}!"` to the end (at the end was important) of my .zshrc file on my Mac (Monterey). The issue only occurred in my IDE IntelliJ IDEA Ultimate, not in iTerm2. I personally preferred "!" over "x". I also had to set: "export LANG=en_US.UTF-8" like mentioned in https://stackoverflow.com/a/20969082/5276779. – flohall Mar 25 '22 at 21:48
-2

Turns out it was a locale issue. Running locale-gen didn't work until I deleted some config file somewhere and reran it.

Your advice is good for the prompt though. Thank you.

  • 2
    You could be more specific on the solution, other users such as me could been having trouble understanding how you have resolved the problem. – Paulo Oliveira Jan 04 '14 at 14:02
  • 3
    I wish I could be more specific, but I originally changed from UTF8 to Latin in /etc/locale.gen and when I went to change it back to UTF8 I started having problems. I deleted a lot of files and I can't find the article that told me exactly which file solved it for me. In the end it came down to having /etc/locale.gen correct and running locale-gen as root. I've installed the new Arch on the same box and haven't had that problem again since. – Concordus Applications Jan 08 '14 at 21:00