Neovim supports a variety of options that can be used to define how Neovim starts up. These options can be used to define the initial buffer content, which configuration file to load, and many others.
The most basic option is to invoke Neovim directly:
nvim
When called with no arguments, Neovim starts up with default configuration, and with an empty buffer. Let's look at a few of the other options that are available.
Starting with File(s) Loaded into Buffers
When called with no arguments, Neovim starts up with an empty buffer. To start Neovim with an existing loaded into a [buffer]] simply add the file's path as an argument:
nvim [path/to/file]
Neovim also supports opening multiple files, by specifying the paths to each of them:
nvim [path/to/file/one] [path/to/file/two] ...
Neovim also supports "globbing", which allows multiple files to be opened on startup by specifying a "blog" pattern. For example, to open all python files located in the current directory, simply type:
nvim *.py
Specifying a Configuration File
Neovim follows the XDG Base Directory specification, which defines a group of environment variables that specify where applications load and store configuration files and other information. This topic is discussed in detail in the configuration section.
However, there are various times when you might want to specify a specific configuration file. For
example, this can be helpful while you are debugging your configuration or developing a
plugin. You can direct Neovim to load a specific configuration file on startup by specifying
the -u
option:
nvim -u [path/to/file]
Read-Only Mode
There are many cases where we want to open and inspect a file, but make sure that we make no changes to it. This is a common command-line action using a "pager" utility, such as less, except provides the benefit of supporting your Neovim configuration, such as your personal keymaps.
Start Neovim in read-only mode by specifying the -R
option and a path to a file:
nvim -R [path/to/tile]
After doing so you will be able to review and navigate through the file, but while you can still make change's you will get warnings, and you won't be able to save those changes (unless you take extra steps to override the read-only feature).
Piping Standard Input to Neovim
Although we tend to think of Neovim as a full-blown application, it is after still a command-line command and can be executed as such. For example, we can create pipelines that read from an input source, transform it in some way, then pipe it into Neovim over stdin so that the buffer contains the transformed content, which can be leveraged to create some very powerful workflows.
As a simple example, let's echo some simple text to stdin, pipe it into Neovim, then save the result to a file. This can all be done with the following command:
echo "Hello World!" | nvim - +':wq output.txt'
The key think here is to use Neovim's -
option to tell it to listen on stdin, then its
+
option that tells Neovim to execute a command (:wq in this case) after loading its
input. Executing this script produces the following file:
Hello World!
this command lists the current directory (ls -a
), then pipes (|
) the result to Vim which is
listening on stdin (-
). While this example is a bit contrived, this demonstrates a simple way to
leverage a wide range of command-line tools to get content into Vim.
Executing Lua Scripts
Neovim has integrated a Lua interpreter, which is used for configuration and plugins, but this allows Neovim to be used as a Lua execution environment. To demonstrate let's look at a simple script:
vim.print("Hello World!")
Which executes, prints a message to stderr, then exits:
Hello World!
Other Options & Getting Help
Neovim supports a wide range of options to control how it starts and which features are enabled. While they may not all be used on a daily basis, it is good to know that they exist and how to find them. You can list some of the common options from the terminal with the command:
nvim --help
or visit the Neovim docs for the complete list.