Vim is a text editor that comes preinstalled with most major Linux distributions. It’s a highly customizable editor and it can be a productivity improvement for developers when utilized well.
Vim encourages the use of keyboards with several keybindings that can operate differently in different modes thereby minimizing the need for a mouse.
Simply put, Vim is an editor that can match the speed at which you think.
Neovim is an extension of Vim. It’s built for users who want the good parts of Vim, and more.
You can read more about the vision of Neovim here.
Note: For the article, we are using LazyVim to configure our Neovim setup. LazyVim makes it easy to customize and extend Neovim’s configuration.
Installing Neovim
There are several ways to install Neovim. This wiki provides several guidelines on how to install Neovim.
I use an Arch Linux machine so it was easy to install Neovim by running the command:
sudo pacman -S neovim
On a Windows machine, you can use Chocolatey by running the command.
choco install neovim
On a macOS machine, you can use homebrew by running the command.
brew install neovim
Once Neovim is installed, we can confirm that it exists by running the command.
neovim
The output should look similar to the image below.
Setting up LazyGit
There are some requirements needed to set up LazyVim:
First, we will clone the LazyVim starter repository into our Neovim runtime path.
~/.config/nvim
is the Neovim’s runtime path for macOS and Linux machines while ~/AppData/local/nvim
is for Windows machines.
Since I am not an Arch Linux machine, I’d run the command below:
git clone https://github.com/LazyVim/starter ~/.config/nvim
Run the command nvim
again to confirm that it is set up.
Basic Plugins Installation
LazyVim comes with a wealth of plugins pre-configured and ready to use. This section of the article will introduce two more plugins that can greatly improve your Neovim experience.
nvim-telescope
This is a highly extendable fuzzy finder over lists. To install this plugin, you can create a new file in the plugins
directory of your Neovim config path named telescope.lua
cd ~/.config/nvim/lua/plugins/; nvim telescope.lua
Then paste the code below into the telescope.lua
file
--telescope.lua
return {
"nvim-telescope/telescope.nvim",
tag = "0.1.5",
dependencies = { "nvim-lua/plenary.nvim" },
}
Then in ~/.config/nvim/lua/config/lazy.lua
you can add this below the last line.
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<C-p>', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
The code above set up keymaps to execute some of the functions provided by nvim-telescope.
The <C-p>
keymap is a Ctrl + p
keybinding that opens a fuzzy finder for files in a modal.
nvim-treesitter
This is a plugin that provides a simple way to use the tree-sitter in Neovim and also provides functionalities like highlighting, etc.
Just like we did for the nvim-telescope plugin, we will create a new file in the plugins
directory of Neovim’s configuration called treesitter.lua
and then paste the code below into it.
-- treesitter.lua
require("lazy").setup({{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "elixir", "heex", "javascript", "html" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
}})
The ensure-installed
is a tuple that includes various languages you want to include the parser support for.
You can see a list of supported languages here.
Conclusion
This is a very basic introduction to getting Neovim set up quickly.
Using Neovim can be very uncomfortable for the first time especially when you have habits that is different from from what Vim preaches. It will be a slow painful start but in no time, you will pick it up.
And do not be overwhelmed with trying to learn everything about Vim for a start. Pick up the barest minimum you need to get started and grow with that.