Vim: Broken colors on start

colorsfontsvimxterm

I'm using uxterm and vim with the following .vimrc: https://github.com/dbrgn/dotfiles/blob/master/.vimrc

When I open a file in vim and don't push any key, colored text is rendered using bold font and the Powerline status line doesn't use any colors.

Screenshot 1

As soon as I push a key (e.g. by switching to insert mode, moving the cursor or pressing EscEsc), the syntax highlighting becomes correct and the Powerline colors show up.

enter image description here

This behavior isn't limited to Python files, it also happens with .txt files which don't use any syntax highlighting. Is this a bug or a misconfiguration in my .vimrc?

Edit: I tried the same thing even with a .vimrc that only contained "syntax on", nothing else. Even then the syntax highlighting colors changed after pressing a key for the first time. This must be either a bug or a missing config variable.

Best Answer

Try placing

set term=xterm-256color

in your ~/.vimrc file and see if it helps.

From my understanding the, problem occurs because when Vim first launches it reads the $TERM environment variable and displays the interface in a "safe" manner to insure that everything it sends to the terminal (all of the escape codes) is supported and all the text will be readable. When the user causes a screen update (by pressing a key, switching modes, ect), it asks the terminal what features it actually supports and then re-displays everything with all of the extra features enabled.

Setting term to xterm-256color forces Vim to assume that some of the more advanced escape codes (colored backgrounds, bold/italics, ect) are supported before querying the terminal.

Related Question