Skip to content

Editing with NvChad

This chapter will introduce some NvChad-specific commands and some standard Neovim (vim) commands. As previously outlined in NvChad UI, NvChad commands are set in the ..nvim/lua/core/mapping.lua file, and allow keys to be used to execute sometimes very long composite commands.

All sequences are started with a primary key followed by an option. The four main keys are:

  • leader = SPACE
  • A = ALT
  • C = CTRL
  • S = SHFT

Just as in the "NvChad UI" document, we will be substituting the actual command to enter, rather than the mappings.

Open a file

To open a file in our editor we can use various methods. We can simply start from the command line by indicating the file name with:

nvim /path/to/the/file

Or open the editor with the nvim command.

If we use the latter method we have several possibilities. We can open a file in the buffer with the command SHIFT + :e + SPACE (edit) followed by the path, or by following the command with the TAB key.

This will show us all the available files and folders starting from the root of the project. It is good to remember that when we use the TAB key in file-opening commands, we can select the file from a convenient drop-down menu. Once this drop-down menu is open, we continue to navigate within it by repeated use of the TAB key.

Command :e + TAB

It's good to remember that each of the commands listed is preceded by SHIFT and followed with a SPACE and either the path or the TAB key. Here is a list of other actions:

  • :view - View the file in read-only mode without the abilitiy to change it. Very good for the protection of critical files.
  • :split - Open the file in an horizontal split screen.
  • :vsplit - Open the file in a vertical split screen.
  • :tabedit - Open the file in a new tab.

In the following example, we have opened the file using :vsplit.

Vsplit Open

Thanks to the work done by the developers of NvChad, we are provided with an additional way to open a file, which is to use the nvim-telescope/telescope.nvim plugin.

This plugin, when used in combination with RipGrep, allows us to search for the file to be opened in interactive mode. By typing the initial characters of the file we are looking for, the plugin will ignore all non-matching files and present us with only those that match our search. This allows for a very smooth search and open process.

To access telescope's find file feature, we need to be in NORMAL mode in the editor and then type: SHIFT + :Telescope fd

<leader>ff

Working with the Editor

Once the file is open we can start editing it. To do this we need to switch to INSERT mode which is activated by pressing the i (insert) key. The mode indicator in the Statusline should change from NORMAL to INSERT, and the cursor placed in the buffer should also change from a colored rectangle to a | pipe.

Now all the characters we type are inserted into the document starting from the position of the cursor. To move the cursor in INSERT mode the Nvchad developers have set up some convenient mappings which are:

  • CTRL + b to go to the beginning of the line
  • CTRL + e to go to the end of the line
  • CTRL + h to move one character to the left
  • CTRL + l to move one character to the right
  • CTRL + j to go to the next line
  • CTRL + k to go to the previous line

Learning all the combinations takes some time but, once acquired, they will make navigation very fast. For example, if we want to edit the end of the next line to where the cursor is positioned we can get to the end of the current line with CTRL + e, and then get to the next one with a CTRL + j and already be in position to add the changes.

Navigation in the document can also be done using the arrow keys on the keyboard, or the mouse.

Text Selection

Text selection can also be done with the mouse and is very convenient, but for this chapter we will use the traditional keyboard-based method.

To select text we need to enter the VISUAL mode. To do this we must first exit the insert mode and switch to normal mode, which is done with the ESC key.

Once we place the cursor at the beginning of the part we want to select, we use the keys CTRL + v to enter the V-BLOC (Visual Block) mode. Now moving with the cursor we will see that our selection will be highlighted. At this point we can work on the selected part of the text.

If we want to copy the selection to the clipboard we will use the y key. If we want to delete iti, the d key. Once the operation is done, the text will no longer be highlighted. For an overview of all the operations that can be performed in Visual Mode you can consult the help directly from the editor with SHIFT + :help Visual-Mode.

Help Visual Mode

To search, the slash character / followed by the search key /search_key is used, which highlights all occurrences found. To move to the next one, the combination / + Enter is used. To move to the previous one ? + Enter.

Once you're finished searching, the highlight can be removed with the command SHIFT + :noh (no highlight).

Find Command

Searches can be even more complex than the one illustrated above; wildcards, counters, and other options can be used. The help command (SHIFT + :help /) can be used to see more options.

Saving the Document

Once the file is created or modified it is saved by first exiting the INSERT mode with ESC and then entering the command SHIFT + :w (write) which will save the file with the current name in the location it is in. If you want to save the file with another name or in another location, just have the command follow the save path:

:w /path/to/new/file_or_position

To save and simultaneously close the editor, the command SHIFT + :wq (write - quit) is used.

In this chapter we have introduced you to the editor. There are many more advanced features than those described here. These features can be consulted on the Neovim help page, or by typing the following command in the editor SHIFT + :help.


Last update: September 5, 2022

Author: Franco Colussi

Contributors: Steven Spencer