Search code examples
vimterminalneovimterminal-emulator

Vim/NeoVim script how to check the terminal emulator


I have two terminals installed on my machine one is ubuntu's default terminal and the other one is alacritty. want to check from which terminal does the vim is opened from. because I can get the alacritty work with the airline so if It is the case i will not use let g:airline_powerline_fonts = 1 and set this variable to zero. How can it be done?


Solution

  • The alacritty terminal emulator usually goes with the $TERM variable set to alacritty (instead of xterm or xterm-256color or a variant.)

    So assuming that's your configuration (you might be getting the incorrect $TERM setting, particularly if you're connecting to a remote box through SSH, or using a multiplexer such as tmux or screen), you can use that in your vimrc to check whether you're running in Alacritty.

    You can check that from the shell:

    $ echo $TERM
    alacritty
    

    Or even from inside Vim, with :echo $TERM.

    If the $TERM variable is indeed set as expected, you can use a snippet like the one below to set the airline variable conditionally on that setting:

    if $TERM ==# 'alacritty'
        let g:airline_powerline_fonts = 1
    endif