Everytime when I start vim in new terminal or use clear command before starting vim, it produces empty lines in terminal. How to fix this?

enter image description here

My term is set to xterm-256color. I cleared my .vimrc, because I thought it was the problem, but it didn't help. I'm using terminator 1.91, but I've also tried default gnome terminal. vim 8.0 and my system is Manjaroo Linux.

  • @Christopher "if [[ ${EUID} == 0 ]] ; then PS1='[\033[01;31m][\h[\033[01;36m] \W[\033[01;31m]]\$[\033[00m] ' else PS1='[\033[01;32m][\u@\h[\033[01;37m] \W[\033[01;32m]]\$[\033[00m] ' fi " – Crocodile Feb 28 '18 at 20:11

It does not produce empty lines.

It moves the cursor to the bottom left-hand corner of the screen, which is where it happens to be sent when you issue a command like :q or ZZ, usually because you have just entered an ex command or because it has updated the status line.

And it only does so because your terminal description in terminfo either does not include capabilities for entering and exiting cursor addressing mode at all, or includes enter/exit cursor addressing mode capabilities that do not employ the DECSM/DECRM Private Mode sequences that command saving/restoring the cursor position in addition to commanding switching to and from the alternate screen buffer, and do not explictly make up for that deficiency by including DECSC/DECRC as well. (DEC Private Modes 1047 and 47 only command switching to and from the alternate screen buffer. It is DEC Private Mode 1049 that commands saving/restoring the cursor position as well.)

Normally, immediately upon exiting vim, like other programs that present a full screen textual user interface, exits cursor addressing mode. Because that restores the cursor position from when it entered cursor addressing mode, back when vim and such programs started up their full-screen textual user interfaces in the first place, the cursor is thereby moved from the bottom left-hand corner to wherever it was when the program started.

That lack of terminfo capabilities, in turn, is most probably because you have not used the correct description for your terminal/terminal emulator. The most common error is to abuse xterm, exactly as you are doing it transpires. Unless your terminal emulator really is the XTerm program, that terminal type is wrong for your terminal. Use iTerm.App, vte-256color, tmux-256color, putty-256color, nsterm, terminator, and so forth, as appropriate.

Note that the terminal emulators that are built into the Linux, OpenBSD, NetBSD, and FreeBSD kernels themselves, denoted by the linux-16color, pccon, and pcvt25 terminal types, do not have alternative screen buffer mechanisms and so do not have terminfo capabilities for entering/exiting cursor addressing mode, and this is the only behaviour that you will get from any full-screen program on such terminals.

Further reading

  • Terminator and gnome-terminal both use the VTE terminal emulator widget. VTE, and hence these apps, set TERM=xterm-256color by default, this is what its developers test it with, and this is what most users use it with. This is not ideal, but the other possible approach (having its own terminal description) has problems too. Out of two problematic approaches the project chose this one. – egmont Feb 28 '18 at 20:41
  • It is, nonetheless, wrong. – JdeBP May 30 '18 at 13:03

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.