0

Normally I'm using the light theme in vim but if I open vim in the tty with the background=light option, than I can't see anything (almost everything is white). So I'd like to set background=dark automatically if I open vim in the tty.

What's the best way to check in vim (with vimscript) if vim is opened in the tty?

3
  • Do you mean "in the tty" as opposed to what... As opposed to using the GUI version of Vim (gvim)? Or do you mean something else (like using vim or ex in some kind of batch mode)?
    – filbranden
    Apr 16 '21 at 3:49
  • 1
    I mean the virtual terminal if you don't run the Xorg server on linux: howtoforge.com/linux-tty-command
    – TornaxO7
    Apr 16 '21 at 6:42
  • 3
    either use a shell script, that acts depending on the output of tty, or use an if condition depending on the $TERM environment variable (for a plain tty, this should be linux, else most likely something like xterm). Ah, I see @Rich has just used that in his answer. Apr 16 '21 at 8:33
3

Not 100% sure if this is what you mean, but for me, when I'm running in the Linux console, $TERM is set to linux, and when I'm running in a terminal emulator it's set to e.g. xterm. (In GUI Vim it's entirely empty.)

So:

if $TERM == 'linux'
  set background=dark
endif

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.