I'm using Cygwin bash prompt, and for long commands the text will wrap around on the same line as opposed to going to the next line despite setting my PS1 to simply ' $'.

Here's a screenshot,

  • 11
    What's the TERM environment variable set to? For the Cygwin console, it should be cygwin. – ak2 May 14 '11 at 5:55
  • 1
    @ak2 this fixed the problem for me, thank you. Cygwin on Mintty. – JoshuaD Nov 20 '13 at 17:55

I was already using MinTTY, and removing the newline in PS1 didn't help either. One piece of advice on this page did help. I executed this bash command:

kill -WINCH $$

In my case, running this once fixed the issue, even after logging out and back in. I'm not sure if this is always the case.

  • 1
    Judging by -WINCH, this signals the bash process that the terminal window was resized. So this should be done after each terminal window resize, I guess. – ivan_pozdeev Sep 26 '13 at 23:18
  • 7
    @ivan_pozdeev, I just found you only have to do this is you resize while vim is open: vim gets the signal and redraws at the new size, but it isn't passed to its parent process and thus bash still thinks the size of the screen is whatever it was when vim opened. – akatakritos Jan 16 '15 at 16:29
  • this also worked for me – konqui Dec 16 '15 at 14:47
  • This worked for me as well, thanks @jtpereyda ! – Jason R. Mick Jul 5 '16 at 14:04
  • Thanks, this was definitely the problem for me--resizing the terminal while in vim. I feel like it should be easy enough to fix this bug but I don't know. – Iguananaut Jan 11 '17 at 14:08

For me, the solution was to add the following lines to .bashrc:

PS1='\[\e[32m\]\u@\h:\W> \[\e[0m\]'
export PS1
export TERM

Note that non-printable characters in the prompt must be enclosed in \[ ... \].

  • 6
    As mentioned by @ak2 in a comment under original question, export TERM=cygwin is sufficient to fix the issue. – dregad Sep 30 '14 at 12:07
  • 1
    it wasn't sufficient in my case. if PS1 contains escape sequences that aren't enclosed in \[...\], the wrapping problem would persist. setting the TERM env variable may be sufficient in your case, but i doubt it. – digory doo Oct 1 '14 at 7:22
  • For me this fixes the problem that the second line overwrites the first line, however unless I use exactly 80 width terminal, the cursor position and text offset are still wonky (using cygwin64 , mintty 2.3.7) – M.M Jun 1 '16 at 1:24
  • Adding \[ ... \] fixed problem for me. – Trismegistos Mar 28 at 10:06

I had the same problem with MinTTY as well. The problem probably has something to do with the primary prompt (PS1).

The solution for me was removing the last 'new line' character from PS1 (right before the '$' sign):

user@host ~
$ echo $PS1
\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$

user@host ~
$ export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\$ '

user@host ~ $

see http://cygwin.com/ml/cygwin/2001-07/msg00140.html for reference.

To make this change persistent, add export PS1='[\e]0;\w\a]\n[\e[32m]\u@\h [\e[33m]\w[\e[0m]\$ ' to your ~/.bashrc file.

  • 1
    Didn't work for me... – HDave Mar 26 '14 at 19:36
  • This did work for me, but in addition to removing the last newline I had to also restart the Cygwin terminal. – christosc Jul 10 '15 at 9:44

As commented by dregad and ak2, setting export TERM=cygwin in my ~/.bashrc file was enough to fix this problem for me.


@jtpereyda's answer is certainly on the mark. But for some reason I couldn't let this go, and dug a little deeper.

Expanding on this comment, if you resize the terminal while in vim (or any other full screen application that takes control of the tty away from the shell), the resulting SIGWINCH is often not sent to the shell, so when it gets back control it doesn't know that the terminal has been resized.

When you resize your terminal it should call an ioctl(..., TIOCSWINSZ, ...) on the master pty that vim is running in. This in turn results in a killpg(SIGWINCH) on vim's process group.

The problem is that vim runs in its own process group distinct from the shell it was exec'd from, so the bash shell does not receive the SIGWINCH and does not adjust its lines/columns appropriately.

If you want a permanent workaround, add shopt -s checkwinsize to your .bashrc. That makes bash check the window size (ioctl(..., TIOCGWINSZ, ..)) after returning from each command, and update its lines/columns.

  • What's vim go to do with the question? OP is not using vim. – DavidPostill Jan 11 '17 at 16:11
  • 1
    I meant to reference a different question that I think made the connection more obvious, but in short a possible cause of the OP's problem is opening a full terminal application like vim, resizing the terminal, and then exiting. As I explained the SIGWINCH is not seen by the shell so when you exit vim it still thinks the terminal is the previous size, resulting in various line wrapping issues. – Iguananaut Jan 11 '17 at 19:47
  • 1
    See superuser.com/questions/283236/… – Iguananaut Jan 11 '17 at 19:48

Something is broken in your terminal settings (probably).
I guess you would have already tried exiting that session and restarting a new one.

While you don't get a solution for the Cygwin terminal, give MinTTY a try (its actually better).

  • 1
    I see this problem in Cygwin across multiple machines, but MinTTY looks better and solves the wrapping problem. Two birds with one stone! – wting May 14 '11 at 21:10
  • Note that MinTTY is the default terminal for Cygwin since late 2011. – Hugh W Mar 22 '17 at 15:43

As commented by akatakritos, you probably resized your terminal while vim was open.

When this happens, just resize the terminal one more time and the issue goes away.

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.