All writing

Neovim for the Casuals

  • neovim
  • tooling
  • editor

Introduction

This is not actually a tutorial. This post is to give you a brief idea of how powerful it is to configure your editor. Maybe you think Neovim is not for you (for now), but it has greatly helped me in understanding my environment, my terminal, and the basics of how code editing works. Therefore I advocate using tools like these to get a better understanding of how things work. It ultimately makes you a good developer.

First step of course is to install Neovim. Check out the installation guide for more details. I would’ve suggested you to use a Neovim distro like AstroNvim, or a starter like kickstart.nvim, but that’s not really the point of this post.

Neovim comes with a lot of default settings, but it definitely doesn’t provide all the features you need. So, how exactly do you configure Neovim?

Well, you write what you want in the configuration file, which is located at ~/.config/nvim/init.lua. Neovim provides Lua as its scripting language (world’s best programming language btw), so we will be writing Lua to configure Neovim the way we want it to look like. I highly recommend you to learn the basics of Lua , it’s a very simple, elegant language. Check out this Lua crash course.

Mix Lua with the Vim API Neovim provides and you’ll have a badass editor that you’ve dreamt of.

Plugins

So, how do you add features to your editor? Well, you can use plugins. Plugins are basically a collection of Lua functions that you can call to add functionality to your editor. For plugin management there are a few options like packer.nvim, vim-plug, but I highly recommend lazy.nvim which of course is developed by the open source/Neovim GOAT folke.

Follow the installation instructions (the structured setup one) and you are ready to install plugins. I highly recommend you to read what you are pasting to your config file from documentation before pasting it, because if you just paste it, you actually don’t learn what’s happening or you won’t understand the environment you’re creating.

Remember — the point is to understand your environment better so you can craft what you want in your editor/environment. Before going further, learn how lazy.nvim works and how Neovim loads Lua plugins via lazy. This is a very important step. Go through the docs properly, or check out The GOAT TJ’s video.

Themes

So, what would you like to add to your Neovim? Well, first of all you want to add a theme that you like. I use Rosé Pine but you can use any theme you want. You can find a list of themes here.

Mine looks like this in my ~/.config/nvim/lua/plugins/theme.lua file:

return {
	"rose-pine/neovim",
	name = "rose-pine",
	config = function()
		vim.cmd("colorscheme rose-pine")
	end,
}

You can add other visual things like status bars, etc. which you can research by yourself — now you know how to do this.

Syntax Highlighting

You would probably want syntax highlighting for your code. Neovim achieves this by using Treesitter. Treesitter is basically a parser that gives Neovim (or any other editor) the ability to understand the source code structure.

Neovim has a Treesitter engine already installed that can load parsers and connect parsers to text in the buffers — you can check using the command :lua vim.treesitter. and you’ll see some Treesitter functions. But what we don’t have in Neovim is the incredible parsers that the Treesitter community has written for so many languages.

So, we need to install parsers for the languages we want to use. For this we use nvim-treesitter, a plugin that allows you to install parsers for the languages you want to use. Read the docs and understand how to install parsers for the languages you want to use. Now Neovim can understand the syntax of the languages you want to use and highlight the keywords accordingly.

My config file looks like this:

return {
	"nvim-treesitter/nvim-treesitter",
	build = ":TSUpdate",
	config = function()
		local configs = require("nvim-treesitter.configs")

		configs.setup({
			ensure_installed = {
				"html", "c", "lua", "vim", "vimdoc",
				"query", "go", "python", "rust", "toml", "sql"
			},
			sync_install = false,
			highlight = { enable = true },
			indent = { enable = true },
		})
	end,
}

LSP (Language Server Protocol)

I don’t want to go into the details of what LSP is, but it basically is a protocol that the text editor client (e.g. Neovim) uses to communicate with the language server to get info about the state of your editor and the state of your code. Your IDE features like go-to-definition, references, auto-completions are all provided by LSPs.

So basically LSP says “hey editor, you can send information about the changes that are happening in the code and what files are open and where the cursor is” and then the language server sends back information like “hey you have an error here” and stuff like that.

Neovim has an LSP client installed but you can’t reap the benefits of LSP without installing a language server for the language you want to use. So that’s where nvim-lspconfig comes in and tells Neovim where the language servers are located, when to start them, and any additional configurations you want to make.

Make an lsp.lua file in your plugins folder and follow the instructions in the docs. You can find my config file here.

Formatting

For code formatting you can use something like none-ls. Unlike the VS Code and coc.nvim ecosystems, Neovim doesn’t provide a way for non-LSP sources to hook into its LSP client. null-ls/none-ls is an attempt to bridge that gap and simplify the process of creating, sharing, and setting up LSP sources using pure Lua.

So you can use non-LSP functionalities like formatting, linting, and code actions with the help of none-ls.

Auto Completion

Auto-completion is one of the must-have features if you want to write code with ease and you want Neovim to be an IDE of some sort. If you want to achieve auto-completions from LSP and other sources I recommend a plugin called blink.cmp.

I use blink.cmp for auto-completion. It supports LSP completions, snippets, buffer completions, and even AI completions. You can find my config file here.

Fuzzy Finding

What we are missing now is a fuzzy finder. That sweet finder that appears when you press Ctrl+P in VS Code. We don’t have that in Neovim by default. So of course we need to install it via a plugin.

Of course the GOAT TJ has a plugin for this: telescope.nvim.


These are probably all you need to start writing code in Neovim. But this is just the tip of the iceberg — there is still a lot more to explore. I would recommend you to check TJ’s videos on Neovim for more details.

Some plugins I recommend

  • A file explorer like VS Code’s tree file explorer on the left side. nvim-tree — I prefer oil.nvim but hey, that’s just me and my silly preferences.
  • The Primeagen’s harpoon — basically a plugin that allows you to bookmark files. I love this plugin.
  • Of course folke’s snacks.nvim for some QOL plugins. Snacks provides a lot of small plugins worth checking out for quality-of-life improvements like the snacks picker, snacks dashboard, and many more.

Check out my config file here to see the plugins I use.

Conclusion

This article just scratched the surface of editor ricing. I didn’t touch on all the crazy autocommands we can write to automate small tasks inside your editor. You can check out my autocommands where I automated listing all error diagnostics in a floating window and many more. That’s how powerful Neovim is. Anything you think, you can achieve. Your imagination is the bottleneck here.

I hope this gives you motivation to learn about your editor, development environment, and the basics of how code editing works. Just through installing an editor like Neovim we got to know how code completions, diagnostics, etc. work. This is why I prefer using tools like these to get a better understanding of how things work. The ultimate goal is to be a better developer, and this certainly helps in that.