45

I use character in my zsh theme's for prompt. But in tmux, my prompt was behaving weirdly, showing extra spaces, like this:

♪ ~   I can type from here
♪ ~ Instead of here like in zsh, and sometimes when I do stuff like cd
♪ ~   cd ~
♪ ~ cdcd /
♪ ~ ^^These 2 chars just show up but are not actually part of command and not delete-able

I recently discovered that I can set tmux encoding to utf8 by set-window-option -g utf8 on. Doing that, the space problem was gone but character changed to _. How can I get my back in tmux?

My zsh-theme:

PROMPT='%{$fg_bold[cyan]%} ♪ %{$fg[blue]%}%c%{$fg_bold[blue]%}$(git_prompt_info)$(git_remote_status)%{$fg_bold[blue]%} % %{$reset_color%}'
Sourabh
  • 1,731
  • 5
  • 22
  • 31
  • I couldn't get `set-window-option` to work for me `not found cmd`. Please, could write exact steps to reproduce it. – user.dz Jan 25 '14 at 12:08
  • I used the tmux conf [here](https://gist.github.com/snuggs/800936) (its also used [here](https://github.com/hoelzro/dotfiles/blob/master/tmux.conf)). It looks like tmux is converting every character that is not ASCII into `_`, when I set that option. – Sourabh Jan 25 '14 at 18:06

3 Answers3

74

Starting tmux with u flag solves this issue

tmux -u

I've created an alias of tmux in my zshrc

alias tmux='tmux -u'
Sourabh
  • 1,731
  • 5
  • 22
  • 31
  • 2
    Thanks for the flag! It was so frustrating with all the gibberish when using tmux and nvim would go crazy with powerline! This solved the issue! Thanks again. – Dave Amit Dec 27 '16 at 07:23
  • For those who what to know why, check [here](http://man.openbsd.org/OpenBSD-current/man1/tmux.1), `-u` `flag explicitly informs tmux that UTF-8 is supported` – shellbye Jan 18 '17 at 09:22
  • 2
    Interesting. I thought setting `set -g utf8 on` in `~/.tmux.conf` would solve this issue, but apparently it didn't. Using the flag explicitly when calling `tmux` does works though. Thanks a lot, you saved me a lot of hassle! – Tim Visee Aug 14 '18 at 15:06
  • 1
    For what it's worth, this recently broke for me, turns out it was due to me adding LC_ALL=C to my config, which forced ascii encoding. – Ehsan Kia Dec 02 '19 at 17:19
  • 1
    Just a note. The setting seems not to be saved in the session. After detatching, one should/can use `tmux -u attach` to set the session to UTF-8. – cojocar Aug 12 '22 at 08:09
11

Thanks for the flag part, but we can also set the below to the profile rc (e.g. .zshrc or bashrc) file

export LC_ALL=en_IN.UTF-8
export LANG=en_IN.UTF-8

With this option set, no need to use the -u flag.

Anant
  • 221
  • 2
  • 2
0

If u use diffrent shell like "fish" or sh u can change enviroment variable of tmux

$ tmux setenv 'LC_ALL' 'en_IN.UTF-8'

$ tmux setenv 'LANG' 'en_IN.UTF-8'

$ tmux show-environment

DISPLAY=:0.0
-KRB5CCNAME
LANG=en_IN.UTF-8                          <-enviroment variable
LC_ALL=en_IN.UTF-8
SSH_AGENT_PID=1269
-SSH_ASKPASS
SSH_AUTH_SOCK=/tmp/ssh-tGUWJ874wmOG/agent.1193
-SSH_CONNECTION
VIRTUAL_ENV=/home/Jai_BholeNath/.tmux.conf
-WINDOWID
XAUTHORITY=/home/Jai_BholeNath/.Xauthority


Hex-Tron
  • 1
  • 1