vlad-ardelean
vlad-ardelean

Reputation: 7622

zsh bug on multiline commands: deleting messes up characters

if i type a multiline command, and run it, all works well. When i press the UP arrow, and want to delete some characters, i see the deletion taking place. If I run the modified command though, i can see that the deletion was all wrong.

Usually it deletes/inserts characters shifted in one direction by one position.

Example:

$ sort file | uniq | grep -v 'some pattern' |less

I want to delete the word file and replace it with other_file. This is what I'll see

$ sort other_file | uniq | grep -v 'pattern' |less

This is what will actually run

$ sort fother_file | uniq | grep -v 'pattern' |less

Notice the name 'fother_file'. This is really annoying, and makes modifying history basically impossible. I end up copy-pasting the code in and out of zsh.

This is my ~/.zshrc file

HISTFILE=~/.zshhistfile
HISTSIZE=40000
SAVEHIST=1000
bindkey -v
zstyle :compinstall filename '/home/shefuto/.zshrc'

autoload -Uz compinit
compinit

if [ -f ~/.aliases ]; then
    . ~/.aliases
fi

export PS1="%{%F{yellow}%}%T]%{%F{green}%}%n%{%F{yellow}%} %~ %{$%f%} "

export WORKON_HOME=~/ve
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
workon tmp2

if [[ -e /etc/bash_completion.d/git-prompt ]]; then
    . /etc/bash_completion.d/git-prompt
fi
setopt PROMPT_SUBST ;
export RPROMPT='%{%F{red}%}$(__git_ps1 2>/dev/null)'

bindkey "^?" backward-delete-char

bindkey -e 

Does anyone know how to fix this?

Upvotes: 0

Views: 904

Answers (1)

chepner
chepner

Reputation: 531165

PS1="...%{$%f%} " tells zsh that $ doesn't advance the cursor, so zsh doesn't have an accurate view of what the prompt length is. You also don't need %{...%} to surround zsh's own escapes, since it knows they don't move the cursor. Try

PS1="%F{yellow}%T]%F{green}%n%F{yellow} %~ $%f "

%{...%} would be for enclosing an explicit sequence of escape characters like \e[32m, which is the ANSI CSI sequence for turning on green text. zsh uses its own terminal-independent sequence %F{green} for this.

PS1=$'%{\e[33m%}%T]%{\e[32m\%}%n%{\e[33m%} %~ $%{\e[0m} '

Upvotes: 2

Related Questions