neovim

Neovim 0.10 colorscheme changes affecting highlighting in terminal


After upgrading to neovim 0.10, some autocommands such as autocmd ColorScheme * hi Normal ctermbg=none have stopped working in terminal. For me this happens in windows subsystem for linux through windows terminal. The reason and workaround is documented below as an answer.


Solution

  • TL;DR

    Explanation

    Neovim 0.10 has this breaking change (source: https://neovim.io/doc/user/news-0.10.html):

    'termguicolors' is enabled by default when Nvim is able to determine that the host terminal emulator supports 24-bit color.

    When termguicolors is enabled, the gui commands become relevant instead of cterm. From this stackoverflow answer (what is the difference between cterm color and gui color?):

    ctermxx is used by console version of Vim (when set notermguicolors). guixx is used in GVim, or in console if set termguicolors, and the console is capable of TrueColor, obviously.

    See also neovim documentation for termguicolors: https://neovim.io/doc/user/options.html#'termguicolors'

    Thus, an autocommand like autocmd ColorScheme * hi Normal ctermbg=none should change to autocmd ColorScheme * hi Normal guifg=none, since now the gui part is relevant even in a terminal. Of course, one could always use both guiand cterm in the autocommands to be safe: autocmd ColorScheme * hi Normal guifg=none ctermbg=none.

    Obviously, the other option is to turn off termguicolors through set notermguicolors