问题是和PS1变量的设置有关
这篇名为<How do I get long command lines to wrap to the next line?>的问题帖,其中有人回答如下:
Make sure all non-printable bytes in your PS1 are contained within \[ \]. Otherwise, bash will count them in the length of the prompt. It uses the length of the prompt to determine when to wrap the line.
See http://mywiki.wooledge.org/BashFAQ/053
在bash中,所有在PS1中的非打印字符都必须用"[]"(不包括引号)将其包围起来,否则在计算提示符长度时也会将其计算在内,导致其无法正确地换行,也就出现了回到行首的情况.
贡献一下我的提示符PS1设置:
PS1="\[\e[35m\]^v^\[\e[0m\]$ \[\e[31m\]\t\[\e[0m\] [\[\e[36m\]\W\[\e[0m\]] \[\e[32m\]\u\[\e[0m\]\[\e[33m\]@\[\e[0m\]\[\e[34m\]\h\[\e[0m\]\n\[\e[35m\]O:\[\e[0m\]\$ "
export PS1="\[\e[32;1m\][\[\e[33;1m\]\u\[\e[31;1m\]@\[\e[33;1m\]\h \[\e[36;1m\]\w\[\e[32;1m\]]\[\e[34;1m\]\$ \[\e[0m\]"
export PS1="\[\e[35m\]^o^\[\e[0m\]$ \[\e[31m\]\t\[\e[0m\] [\[\e[36m\]\W\[\e[0m\]] \[\e[32m\]\u\[\e[0m\]\[\e[33m\]@\[\e[0m\]\[\e[34m\]\h\[\e[0m\]\n\[\e[35m\].O.\[\e[0m\]\$ "
网友评论