When I used vim outside a unix screen to edit a file, vim displays the file correctly. However , when I open the same file inside a unix screen, the indentation "seems" to become messy.

I say "seems" because the indentation is actually correct (if you see the highlighted cursor in the second image, it is actually at the correct begin-of-the-line)

What can be the issue here ?

EDIT : Not just my file, even the vim messages seems messy enter image description here I have tried all things possible, also chnaged code for CRLF in screen code, but couild not get rid of this issue. Finally switched to tmux, and it works well.

Outside screen: Outside Screen

Inside screen: Inside Screen

  • make sure you have the env variable TERM=screen when inside screen.
    – meuh
    Commented Oct 13, 2016 at 17:39
  • thanks @meuh , but that does not help ...
    – amisax
    Commented Oct 14, 2016 at 5:43

1 Answer 1


The picture appears to show these features working:

  • color (perhaps)
  • cursor-addressing (something moved the cursor to the right place)
  • tabs (unknown: if the terminal was claimed to support hardware tabs but did not at all, that second line would begin at the left margin)

But that second line is the problem. Vim could have attempted to move the cursor straight down from the curly brace (with a line-feed) and gotten a carriage-return / line-feed instead. That could explain the space, and vim does this type of optimization in screen.c:

    else if (plan == PLAN_NL)
        if (noinvcurs)
        while (screen_cur_row < row)
        screen_cur_col = 0;

In your stty settings, that would be onlcr:

 onlcr (-onlcr)
             Map (do not map) NL to CR-NL on output.

which seems to be off normally. One of your stty settings may have confused vim (or screen) so the result is as shown.

For example, in a quick check I did this (with a literal tab character)

$ stty ocrnl
$ cat >foo
$ cat >foo <<EOF
if(a) {
        /*then b */
$ vim foo

and see this (demonstrating that vim can be confused by the setting of ocrnl):

if(a) {
        /*then b */


But then (quitting vim) and

$ stty -ocrnl
$ vim foo


if(a) {
        /*then b */

For what it's worth, vi-like-emacs does the right thing in this case.

  • Thanks ! This definitely seems to be the right direction. However I could not do a stty -onlcr as even after doing it the stty -a shows it to be on. I think screen is tampering with that setting internally.
    – amisax
    Commented Oct 14, 2016 at 5:38
  • Odd - I see it the reverse. What type of system are you using? I was using Debian for my followup example. Commented Oct 14, 2016 at 8:33
  • I am on RHEL ( 2.6.32-504.16.2.el6.x86_64 ) . I think there is something in the/etc/screenrc file that is messing things up.
    – amisax
    Commented Oct 14, 2016 at 11:32
  • Perhaps, but (a) my CentOS 6 shows the same default stty settings and (b) the misbehavior of vim is consistent with my quick check. CentOS 6 is equivalent to your Red Hat system. Commented Oct 14, 2016 at 23:23

You must log in to answer this question.

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