Neovim 101 — Terminal and Shell
We talked about terminal and shell in general previously. In this article, let’s understand how the terminal and Neovim work together. We will also configure the terminal emulators to work better with Neovim.
This article is part of the Neovim 101 series.
The Neovim configuration files are available in this repository.
Neovim uses a list of terminal capabilities (
:h tui) to display its user interface. If that information is wrong, the screen may be messed up or keys may not be recognized.
It guesses the terminal type when it starts (
:h startup-terminal). The
$TERM environment variable is the primary hint that determines the terminal type.
$TERM environment variable (Neovim 101 — Terminal and Shell
:h $TERM) must match the terminal we are using. Otherwise, Neovim cannot know what sequences the terminal expects, and weird or sub-optimal behavior will result (scrolling quirks, wrong colors, etc.).
Historically, terminal emulators could not distinguish between certain control key modifiers and other keys (
:h tui-csiu). For example,
<Tab> are represented the same way, as are
<C-J>. This meant that Neovim also could not map these keys separately.
Control Sequence Introducer (CSI)
A CSI control sequence looks like the following
0x1B + "[" + <zero or more numbers, separated by ";"> + <a letter>
For more details on the format, check out this Wiki.
0x1B represents the ANSI escape code. ANSI escapes always start with either