I spend half the time in a TTY (Linux console as in Ctrl+Alt+F2) and the other half in a X session. Unfortunately the color scheme I use for NeoVim in the graphical environment on xterm does not look good in the Linux console interface. Since the colors do not look the same in the TTY, some elements are not really readable or easy on the eyes with this scheme.

To get around the problem I use a script which tests the $TERM variable and adds the line for the color scheme in my init.vim before running NeoVim: if $TERM equals something else than linux the script adds the commands colorscheme ... to the config file. This way I start NeoVim with the default color scheme if the command nvim is issued in a Linux console; and with the specified color scheme if the command is issued in any other terminal emulator (xterm in my case).

I was wondering if there wasn't a more elegant way to go. I would like to implement this test in my init.vim without having to rely on a external program.

  • Welcome to Vi and Vim! Can you share more details please? By tty do you mean a Linux console (as in Ctrl-Alt-F2 etc.)? What do you set $TERM to? What about color scheme, why do you feel you need a different one for tty vs. X? On X do you use a NeoVim GUI or do you just run NeoVim on a terminal like xterm, rxvt, GNOME Terminal, Konsole, etc.? If so, which?
    – filbranden
    May 17, 2020 at 20:54
  • 1
    Thank you @filbranden! I tried to clarify a little bit.
    – user29638
    May 17, 2020 at 21:12

1 Answer 1


I think the simplest thing to do is edit your vimrc/init.vim and test $TERM:

if $TERM ==# 'linux'
  " commands
  colorscheme ...
  " more commands
  colorscheme ...
  • 1
    That's perfect! I thought Vim/NeoVim did not have access to the environment variables because I had troubles with user-defined variables. Looks like it is working with system-wide variables. I use $TERM !=# because I want a vanilla Vim in a TTY. Thanks!
    – user29638
    May 17, 2020 at 21:27
  • @LoïcReynier as long as the variables are exported (in the environment), you’ll be able to access them (IIRC)
    – D. Ben Knoble
    May 17, 2020 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.