Terminal in neovim

:bulb: See :help terminal-emulator in neovim for more info

Ocasionally I will sideline my WM1 (XMonad) or terminal multiplexer (tmux) in order to start a terminal session in nvim itself.

Sometimes it pays to use neovim’s builtin terminals because

  • when already in neovim and in need of a terminal in order to quickly move forward with whatever it is I’m trying to do, it is convenient to spawn one and get shit done :poop:
  • moving the neovim window around between workspaces or displays will always keep the related terminal close (i.e: I don’t have to move two windows around) or consider how to move the editor into a tmux session and then split it
  • yanking text between buffers is a breeze

Start a neovim terminal through the :terminal command in neovim. You’ll get dropped into insert mode so do yourself a favor and use the Ctrl+\ Ctrl+n sequence to exit into normal mode. Of course, once in normal mode you may return to insert mode using any of the keybindings that you’re most comfortable with (in my case a or i).

Another, perhaps more practical, way to spawn a terminal is by using the term scheme. Opening a file prefixed with term:// will result into the section prefixed by the term:// to be executed in the terminal as in

  • :vsplit term://zsh spawning a zsh :ocean: shell :shell:,
  • :split term://htop spawning htop in a terminal and
  • :edit term://bash spawning a bash shell :shell:.

Note that navigating between neovim windows is only possible in normal mode. Which should make sense when you think about it. It isn’t much different when editing text in vim-ish editors. The terminal-emulator help page documents how you may define mappings using :noremap and :tnoremap to specify mappings to navigate windows within any mode.

So in conclusion,

  • use the :terminal command to spawn a terminal or
  • open a term://* file, where * represents the executable to call in the terminal,

and remember the following mappings for convenience’s sake:

  • <C-\><C-N> to switch to normal mode2
  • <C-l> to redraw3
  1. window manager 

  2. Ctrl+\ then Ctrl+N 

  3. Ctrl+L