Neovim 101 — Code Outline
In this article, let’s go through the different solutions that allow us to visualize and easily navigate the source code.
This article is part of the Neovim 101 series.
The Neovim configuration files are available in this repository.
Getting Started
As programmers, we always need to jump around to find or view where identifiers are defined and used. By default, Vim provides a way to do this. With the Tree-sitter and LSP features provided by Neovim, this has been made even easier for us.
In this article, we will go through the different ways to visualize and navigate the source code.
Tags
Traditionally Vim uses tags to jump around to find the identifiers.
A tag is a location where an identifier is defined. An example is a function definition in a C or C++ program. A list of tags is kept in a tags file. This can be used by Vim to directly jump from any place to the tag, the place where an identifier is defined.
To generate the tag file, we need to install and use universal-ctags
.
Let’s go through an example. In the screenshot below, we use the ctags
command to generate the tags for the Python files.
The ctags
command generates a tag file in the same folder.
From Vim/Neovim, we use the :tag
(:h :tag
) command to navigate to a particular tag.
We use the :tags
(:h :tags
) command to show the content of the tag stack.
Below are other common commands for tags.
CTRL — ]
— Jump to the tag of the word that is under the cursorCTRL — T
— Go to the previous tagCTRL-W ]
— Split the current window and jump to the tag under the cursor