1

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 Oct 13 '16 at 17:39
  • thanks @meuh , but that does not help ... – amisax Oct 14 '16 at 5:43
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)
        screen_stop_highlight();
        while (screen_cur_row < row)
        {
        out_char('\n');
        ++screen_cur_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 */
}
EOF
$ 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

shows

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 Oct 14 '16 at 5:38
  • Odd - I see it the reverse. What type of system are you using? I was using Debian for my followup example. – Thomas Dickey Oct 14 '16 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 Oct 14 '16 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. – Thomas Dickey Oct 14 '16 at 23:23

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.