Neovim — editor configuration: basic setup
Greetings!

Today we’ll start configuring our console editor Neovim to our preferences. The note will be small)

Neovim is an evolutionary development of the classic Vim editor. To understand what this Vim thing is and why it’s needed — read my previous article: VIM — Console editor: an introduction. In that article I tried to bring readers up to speed: I briefly described the editor itself, its modes of operation, and gave frequently used hotkey commands.

Today we’ll perform the initial configuration of the Neovim editor. Note that the configuration from this article is also valid for Vim, with a few exceptions.

It won’t hurt too much, so please, hit the jump)

Preface

You can configure Neovim in two ways:

For better compatibility with classic Vim, I’ll be doing the configuration using the first option. But I might switch to Lua in the future)

As usual, all actions in the article will be performed in a Linux Mint environment, specifically version 21. All articles related to this distribution can be found by tag.

If Neovim isn’t installed yet, let’s fix that)

Installing Neovim on Linux Mint

Open the terminal and run the command:

BASH
sudo apt update && sudo apt install -y neovim
Click to expand and view more

If anyone’s interested in the terminal appearance — the Nord color scheme is used. I talked about the setup in the article: Customizing Linux Mint 20/21 + Nord theme.

The terminal uses a configured Zsh shell — there’s a separate article about setting it up: ZSH — Interactive command shell for Linux + Oh-My-Zsh.

Basic Vim/Neovim configuration

For Neovim, create a config folder and open the file for editing:

BASH
mkdir ~/.config/nvim

nvim ~/.config/nvim/init.vim
Click to expand and view more

For classic Vim, the command is:

BASH
vim ~/.vimrc
Click to expand and view more

In vimscript, comments are denoted by an open double quote character ". This is hyper inconvenient, and apparently in recent Neovim versions you can use the hash #, but for compatibility we’ll leave the default.

And add the following content:

BASH
" By r4ven_me

" ############################
" ###### BASIC SETTINGS ######
" ############################

set mouse=a                 " Enable mouse support
set encoding=utf-8          " Set character encoding to UTF-8
set number                  " Display line numbers
set scrolloff=7             " Keep at least 7 lines visible above/below cursor
"set noshowmode              " Disable mode display
set cursorline              " Highlight the current line
set ignorecase              " Enable case-insensitive searching
set smartcase               " Use smart case for searching
set laststatus=2            " Always show status line
set tabstop=4               " Set tab width to 4 spaces
set softtabstop=4           " Set soft tabstop to 4 spaces
set shiftwidth=4            " Set indentation width to 4 spaces
set expandtab               " Use spaces instead of tabs for indentation
set autoindent              " Enable automatic indentation
set fileformat=unix         " Set file format to Unix (LF line endings)
"set showtabline=2           " Always show tabline
set clipboard=unnamedplus   " Use system clipboard
"set termguicolors           " Enable true color support
set splitbelow              " Split new windows below the current one
set splitright              " Split new windows to the right of the current one
set equalalways             " Keep window sizes equal
set sessionoptions-=blank   " Don't save blank windows in sessions
filetype indent on          " Disable automatic indentation for specific filetypes
Click to expand and view more

Neovim configuration file

As you can see, I left comments in English next to each item (for universality).

For the changes to take effect, just save the file and re-enter the editor:

BASH
:wq

nvim ~/.config/nvim/init.vim
Click to expand and view more

Let’s give a description of each parameter in English)

So:

ParameterDescription
set mouse=aEnables the use of the mouse in the editor.
set encoding=utf-8Sets the encoding for new files to UTF-8.
set numberEnables display of line numbers.
set scrolloff=7Sets the number of lines displayed after the cursor when scrolling through the file.
"set noshowmodeDisables display of the current editor mode status (leave this parameter commented out, we’ll need it in the future when configuring the statusline plugin).
set cursorlineEnables highlighting of the current line.
set ignorecaseDisables case sensitivity when searching via / and ?.
set smartcaseWith this parameter, the search will be case-insensitive if the query contains only lowercase characters. However, if the query contains at least one uppercase letter, the search will be case-sensitive.
set laststatus=2Enables display of the status line at the bottom of the window.
set tabstop=4Sets the indent width when pressing Tab to 4 spaces.
set softtabstop=4Determines the number of spaces to be inserted when Tab is pressed, or when automatic indentation occurs. It’s called “soft” because it doesn’t change the actual text, but only visually sets indentation.
set shiftwidth=4Determines the number of spaces inserted when adding auto-indents.
set expandtabReplaces the tab character (set by default) with spaces.
set autoindentEnables auto-indentation when moving to a new line.
set fileformat=unixSets the format for new files. These formats mainly differ in how the line break character is handled. You can read more about formats, for example, here.
«set showtabline=2Enables permanent display of the tab line, even if only one window is open (this parameter will also be useful for us when configuring plugins in the future).
set clipboard=unnamedplusActivates the use of the external clipboard (with this parameter, classic vim may behave incorrectly, but in neovim everything works fine).
"set termguicolorsEnables true color support for the terminal. This parameter can also be left commented out. It will be needed in the future when configuring the color theme for Neovim.
set splitbelowInstructs the editor, when horizontally splitting a window with the :split command, to open the new window below (by default, above).
set splitrightInstructs the editor, when vertically splitting a window with the :vsplit command, to open the new window to the right (by default, to the left).
set equalalwaysWhen this parameter is enabled, the editor will try to automatically maintain equal width of vertical windows when they are opened.
set sessionoptions-=blankRemoves the “blank” option from session parameters. Disables saving/restoring blank windows when working with session files.
filetype indent onEnables automatic indentation depending on the file type.

Description of basic parameters

All the parameters listed above can also be temporarily activated/deactivated manually while working in the editor. To activate, simply enter the parameters listed above in command-line mode (invoked with the colon key :, i.e. Shift + ;). For example, to enable line number display:

BASH
:set number
Click to expand and view more

And to deactivate:

BASH
:set nonumber

# or

:set number!
Click to expand and view more

This syntax applies to many parameters. To disable, you need to add the no prefix or the ! suffix before/after the desired parameter.

Afterword

This was the first part of the basic Neovim configuration. As you can see, even when configuring such a small list, you can understand how flexible the settings the editor offers are.

In the next article we’ll talk about setting up swap and backup files to ensure safety when working with files in case of power outages or disk write problems, etc. Don’t miss it.

Thanks for reading. Good luck learning Vim/Neovim.

Useful sources

Other articles of mine:

Copyright Notice

Author: Ivan Cherniy

Link: https://r4ven.me/en/dots/neovim-konfiguraciya-redaktor-bazovaya-nastrojka/

License: CC BY-NC-SA 4.0

Blog materials may be used with attribution to the author and source, for non-commercial purposes, and under the same license.

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut