Providers

Neovim uses providers to implement some features whose behavior may depend on the system and environment, such as clipboard support.

Different systems have different ways of exposing their clipboard. For example, on macOS, the pbpaste and pbcopy commands allow you to get and set the clipboard; whereas on Linux, you can use either xclip or xsel to get and set the X11 clipboard. If you’re running an operating system headlessly, there may not even be a system clipboard with which to interact.

Use providers to interact with Python, etc.

:py3 print('hello world')

Packages

Packages are a new feature in Vim 8 that make it easy to manage your plugins. To put it simply: a package is a directory that contains one or more plugins. In turn, a plugin is a directory that contains one or more scripts, and a script is a standalone file containing instructions written in Vim script.

Helptags

When you add a plugin to one of your packages, all you need to do to start using that plugin is restart Vim. But if you want to consult the documentation for a newly installed plugin, you have to do one more thing: index its documentation. You do this with the :helptags command.

make command

You can use this to run a build that’s configured by a Makefile, but you can also use the :make command to run other types of builds. Using Vim’s compiler plugins and the :make command, you can run a build tool and capture the output so that you can refer to it later.

To use the :make command, you need to configure two options: ‘makeprg’ and ‘errorformat’. You typically put a mylang.vim script in the after folder $VIMCONFIG/after/compiler and set the current compiler using :compiler rust

The killer feature of the :make command is that it populates the quickfix list, allowing you to navigate easily between any error messages. Using a plugin such as Dispatch one could benefit from the async version of :make, called :Make.

Quickfix list usage

You open the quickfix window using the :copen command. You can traverse the list of errors using the commands: :cfirst, :cprev, :cnext, :clast. These commands allow you to quickly jump between errors, fixing them as you go.

Terminal emulator (Neovim)

  • If you want to run a single command line, you can use :!{cmd}.
  • If you want to run a series of commands, you can use <C-z> to suspend Neovim while fg in the shell brings it back

When you run a shell inside of Neovim, you can interact with the shell’s scrollback using Normal mode commands:

  • You can scroll and search using familiar keyboard mappings.
  • You can use text objects to select a range of text.
  • You can yank and paste using any of Neovim’s registers.
  • You can jump to a filename under the cursor using the gf command.

Terminal mode and terminal buffers buffers

Terminal mode is a mode, just like Normal mode, Insert mode, etc that can only be used in terminal buffers, where Insert mode is not available. Just as nnoremap lets you create mappings for Normal mode, tnoremap lets you create mappings for Terminal mode.

A regular Vim buffer usually corresponds to a file on disk, whereas a terminal buffer corresponds to a process. You can’t directly modify the text in terminal buffer (such as using dd). Depending on what program is running within, you may be able to indirectly modify the contents of a terminal buffer by interacting with the underlying program. To interact with the program running inside a terminal buffer, you activate Terminal mode.

As a final note, Vim also has Command-Line mode, which shouldn’t be confused with Terminal mode. You can activate Command-Line mode from Normal mode by pressing /, ?, or :.

Sending commands to terminal buffers

You can get the b:terminal_job_id buffer variable which you can retrieve using :echo b:terminal_job_id and then call :call jobsend(job_id, "echo foo\<CR>"). You can create a custom name for the command using `:command! Foo call jobsend(job_id, “echo foo<CR>”)“

Scrolling

These are the most useful commands for scrolling in (Neo)Vim

<C-e> Scroll down one line

<C-u> Scroll up half a page Scroll down half a page <C-b> Scroll up a page ` Scroll down a page

Avoiding nested instances

Because Neovim supports :terminal command, it is possible to open a neovim instance in a terminal inside Neovim, however this is not desirable.

To avoid this, we can use nvr to replace opening a new instance of Neovim within a buffer with a new buffer in the existing window. The way to achieve it is to set override the environment variable $VISUAL via vimrc, since this variable will be injected in the terminal like so

​ 	​ifhas(​'nvim'​) && executable(​'nvr'​)
​ 	  ​let​ $VISUAL="nvr -cc split --remote-wait +'set bufhidden=wipe'"
​ 	​endif

Autocommands

Autocommands can be usedf to react on event such as buffer open, buffer edited, etc.

You can use special variable <afile> <abuf> <amatch> to target a command to to a specific file, buffer or match that triggered the autocommand. An example in Vimscript looks like the following:

augroup demo
autocmd!
autocmd BufNewFile,BufReadPost vimrc,*.​vim​
​ 	​        \echo'Editing Vim script: ' . expand(​'<afile>'​)
augroup END
 

Note that the autocmd! inside an auto-command group is a best practice so that if the script is sourced twice with :source my-autogrup.vim the autocommands are not bound twice tothe event

Others

:lcd changes the current working directory