Loading ...
Sorry, an error occurred while loading the content.

120632Re: Determining if Vim is running in text-console mode or X Windows

Expand Messages
  • Benjamin R. Haskell
    Feb 1, 2011
      On Wed, 2 Feb 2011, Steve Laurie wrote:

      > [...]
      > Both in text console and in gnome-terminal, :echo $DISPLAY returns 0
      > (int, not a string) - still no difference between tty text mode and
      > terminal emulator.

      Maybe I'm misunderstanding something in your response, but you shouldn't
      test the return value of echo. Test the $DISPLAY env var:

      if exists('$DISPLAY')
      " running under X11
      " running on console

      > I have had some success using:
      > if &term=~'cons25'
      > colorscheme myvim
      > elseif &term=~'xterm'
      > set t_Co=256
      > colorscheme calmar256-dark
      > endif
      > but the strange thing is, if $TERM is set to xterm and not xterm-256color,
      > gkrellm locks up... something to do with the email part of it.
      > If I could just find where xterm is being set and change it to xterm-256color
      > without altering tty mode's TERM settings (i.e. cons25) I'd be laughing.

      For me, here are some environment variables that are different between a
      shell running on a virtual console and a shell session running under
      rxvt-unicode under X11:

      X11: TERM=rxvt-unicode256 console: TERM=linux
      X11: SHLVL=4 console: SHLVL=1

      These are not present at all on a vt:


      You shouldn't have a DISPLAY variable set under a console session, as
      it's meaningless. (Doesn't mean you won't get one -- might be
      erroneously set up by default.)

      You're also right to question a TERM=cons25 when running under X11; that
      sounds as broken as $DISPLAY. Do you have something in a .profile,
      .bash_profile, or .bashrc?

      Actually, on a FreeBSD box that I have access to, the .profile file from
      /etc/skel/ has:

      TERM=cons25; export TERM

      Maybe that's the problem.

      Otherwise, I would think $SHLVL and $WINDOWID would be your best


      if exists('$SHLVL') && $SHLVL < 2
      " probably running on console
      " running under X11


      if exists('$WINDOWID')
      " under X11
      " on console


      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Show all 15 messages in this topic