History commands render incorrect on Bash Vi mode
-
29-09-2020 - |
Question
I'm having this werid and really annoying issue in bash vi-mode.
Env:
Mac 10.9.2, iTerm 2 1.0 or Terminal.app, $TERM={screen-256color|xterm-256color|xterm|vt}
Repro steps:
- Run some long commands (like 'some_long_commands_long_long')
- Press Esc and then press k.
The issue is:
I do see "some_long_commands_long_long" on my command line. But the cursor is not located at the beginning, instead it's on the 12nd char, see screenshot
If I press A to append some other text, the cursor will go beyond the command, which means the REAL command is start from where the cursor is located at the first place, the rendering is wrong.
I searched on google but ended up with nothing..... Anyone has a better idea about this? Thanks a lot...
Solution
After debugging for quite a while I finally figured it out. It's an issue caused by PS1. Basically I forgot to wrap my colored ">" with "\[" and "\]".
OTHER TIPS
Based on comments in Stackoverflow, IMHO the problem is in a tmux/iTerm/settings combination, not in the bash
itself. you should try solve the problem step-by-step:
- start native
Terminal.app
with a clean~/.profile
and~/.tmuxrc
- try
set -o vi
withouttmux
- if it is works, (should) - switch to
iTerm
and check again (should works) - start
tmux
inTerminal.app
and iniTerm
and compare... both should works. - step-by-step enable your
.tmuxrc
config...