2

I've been having this issue for some time now, and it is really annoying, but I can't figure out what's wrong. When I start a tmux session on my terminal, no matter if it is on Terminal.app or iTerm2, I always get a weird space between the prompt and the text I type, roughly 3 times the space I get outside tmux. This wouldn't be a big issue by itself, but when I try to press backspace to delete something or use vi mode (zsh) to modify something, the cursor displays as if the text was in the right position (the way it displays outside tmux) but the text is on the wrong place, so it is impossible to know what I'm actually modifying. Also, when I press enter, I can see the text blink to the right position, but this isn't really useful at that point.

I've tried reporting the $TERM type with different options when I start tmux, but none of them seem to make it better.

Does anyone know what the issue could be?

EDIT: This is my $PROMPT/$PS1: %{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}

  • Do you have multibyte characters in your prompt? Is the utf8 window option turned on for your tmux windows? – Chris Johnsen Sep 30 '13 at 2:27
  • @ChrisJohnsen I believe I have the utf8 window option turned on, as I set these two lines on my tmux.conf trying to solve the issue (and as far as I know this is what should enable it) set-option -g status-utf8 on setw -g utf8 on. As for the multibyte characters, how should I check this? – uorbe001 Sep 30 '13 at 18:51
  • When looking for multibyte the prime suspects would be “fancy” shapes like arrows, triangles, accented characters, etc. If you output them to tmux when it has utf8 turned off, then its idea of the cursor position and the outer terminal’s idea of the cursor position will be different; zsh asks for the cursor position, so it is sensitive to this discrepancy (which shows up as extra spaces at the end of its prompt). You might want to edit your question to include your actual PROMPT/PS1 value. – Chris Johnsen Oct 1 '13 at 1:25
  • @ChrisJohnsen I do have "fancy" shapes, I'm editing the original post to include my PROMPT value as suggested :) – uorbe001 Oct 1 '13 at 8:34
  • Are you sure you have not turned off utf8 for that window (despite having the global value be on)? I certainly see extra spaces when using your PROMPT value if I set utf8 off for the window. What does tmux show -w utf8 \; show -gw utf8 show in a window you are having problems in? – Chris Johnsen Oct 1 '13 at 9:32
3

I have seen a problem like this when using multi-byte (UTF-8 encoded) characters in the prompt, but only when tmux’s utf8 window option is turned off.

To identify such characters look for any “fancy” shapes, special symbols, or accented characters that are outside the ASCII repertoire (i.e. any Unicode codepoint beyond U+007F).

To check whether the utf8 option is active use this command in a window that is having the problem:

tmux show-option -gw utf8 \; show-option -w utf8

(or at a tmux : prompt without the leading tmux and without the backslash)

If it shows two values, then the second one is the active value for that window. The first (or only) value is the global value that will be used if there is no window-local value established.

If you are seeing a different value from the one established by your configuration file, then you probably need to restart your server (or iff the changes made by your configuration file are idempotent, then you can source it: tmux source ~/.tmux.conf).


The problem arises because (without utf8 enabled) tmux and your external terminal emulator have a different idea of how many columns are used to display each multibyte character. tmux expects a multibyte character to take up multiple columns (one for each byte), but your external emulator is probably configured to recognize it as a single UTF-8 character and thus will render it in a single column.

The problem is especially visible in a zsh prompt because zsh is careful to track where the cursor is so that is knows when the line will break and what it needs to do to properly redraw the prompt. Unfortunately, the mismatch between (non-utf8) tmux and the (UTF-8 configured) external emulator causes tmux to report a cursor position that is several columns to the right of the expected position (one extra space for each extra byte in every multibyte character in the prompt).

Enabling utf8 in tmux fixes the problem because both tmux and the external emulator will recognize the sequences for each multibyte UTF-8 codepoint as taking up a single column. Reconfiguring your external emulator to use a single-byte encoding would also fix the discrepancy, but at the cost of not being able to properly view UTF-8 encoded data (although such a view does basically show you what tmux is “thinking” when utf8 is off).

  • 1
    In my case, I didn't notice I had some tmux sessions opened on the background by already closed shells, I found them by running tmux list-sessions and I simply killed the tmux process. Tmux only reloads the tmux.conf file when the server restarts, so my changes on the conf were not being loaded. – uorbe001 Oct 3 '13 at 8:19
  • When I set utf8 in tmux, vim stops printing the correct utf8 characters! I seem to be able to (a) have vim display the correct characters but have lines wrapping and content all over the place, or (b) have layout fixed but not get the right characters! – artfulrobot Jul 7 '14 at 18:58
  • @artfulrobot: You probably should start a new question, your situation will depend on your Vim settings (e.g. tenc, fenc, enc, etc.) and possibly your environment (e.g. LANG, LC_CTYPE, etc.). – Chris Johnsen Jul 7 '14 at 20:46
  • 1
    Quick update: utf8 option is removed in newer versions of tmux – Mario Aug 10 '16 at 16:50
0

I had the exact same error in Terminal.app. What fixed it for me was to go to "settings/settings/advanced" and change "Declare terminal as" to xterm-256color. No idea why :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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