I'm not sure if I'm missing some sort of configuration here, but occasionally my cursor is unable to return to beginning of line where command starts. If I press FN+leftArrow, it goes few characters after beginning of command, if I press FN+rightArrow, ot goes way behind end of line. It seems like it thinks that whole line is shifted to the right. See screenshots attached. I was unable to reproduce this on purpose. It happens woth all kind of different commands pretty nondeterministically :-(. Any ideas are welcomed, thanks. FN + left arrow FN + right arrow


  • 1
    Does this happen if you use a less heavily modified shell prompt? Try switching to a super vanilla shell setup.
    – Ian C.
    Oct 8, 2016 at 18:12
  • You mean like plan cmd prompt, not customized one? Oct 8, 2016 at 18:33
  • Yes. If this is bash, try something like for f in ~/.bash{rc,_profile}; do mv "${f}" "${f}.save"; done and then get a new iTerm2 window. Do you still have the problem after doing that?
    – Ian C.
    Oct 8, 2016 at 18:38
  • Well, that helped :-). However, is there a way how to keep custom cmd prompt and resolve this issue? I'm still unclear why this is happening. I use customized cmd prmpt: export PS1="$(tput bold)$(tput setaf 6)\t [\W]$(tput sgr0): " Oct 8, 2016 at 18:59

2 Answers 2


So our debugging session has determined it is your prompt customization, not iTerm2. You said your prompt customization is:

export PS1="$(tput bold)$(tput setaf 6)\t [\W]$(tput sgr0): "

The simple answer is don't use tput to customize your prompt. It's the sgr0 reset command that's likely doing more than you want it to do and screwing up buffered text movements.

Let's try doing this with ANSI codes directly. If you use an ANSI color scheme setup like this you can try:

export PS1="${normal}${bold_blue}\t [\W]${normal}: "

That works perfectly for me with Fn-arrow combinations for navigating the line.

tput is a neat idea, but it comes from the ncurses package which is a very advanced way of doing UIs in command prompt interfaces by exploiting all kinds of terminal stuff. Best to just stick to ANSI here.

  • One last thing. I'm trying this prompt, but it gives me error ': bad substitution': export PS1="${color reset}${color blue bold}\t [\W]${color reset}: ". Any ideas? Oct 8, 2016 at 19:46
  • Well color is a function call but you're trying to use it as some sort of variable reference. Try export PS1="$(color reset)$(color blue bold)\t [\W]$(color reset): " instead.
    – Ian C.
    Oct 8, 2016 at 20:51
  • Ah, I see now. I actually didn't import any other scripts from GitHub link. I thought that color was actually some sort of command (although it didnt work in bash nor zsh). Now I see it's a function. I'll play with it more and we'll see what I can get working. Thanks for all the help :-). Oct 8, 2016 at 21:04
  • If this doesn't work, put a \[ before each non-printing sequence (i.e. a color code variable) and a \] afterward.
    – 0942v8653
    Oct 8, 2016 at 21:12
  • I had the same symptoms without tput. For me the solution was to change e.g. $BOLD to ${BOLD} in the variable references in my PS1: RED='\[\033[31m\]' GREEN='\[\033[32m\]' YELLOW='\[\033[33m\]' BLUE='\[\033[34m\]' MAGENTA='\[\033[35m\]' CYAN='\[\033[36m\]' BOLD='\[\033[1m\]' NORMAL='\[\033[0m\]' INVERT='\[\033[7m\]' UNINVERT='\[\033[27m\]' export PS1="${BOLD}\$(which_newton)${NORMAL}${BOLD}\$(git_branch)${BLUE}\$(gradle_status)\W/${NORMAL} $ "
    – kotoole
    Mar 17 at 15:51

I ran into the same problem, with exactly the same things (iTerm, bash, and tput). I added $(tput sgr0) to the front and start a bash sub shell, the problem goes away and Ctrl + A and Ctrl + E work all properly from then on.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .