Timmy Xiao

home ยท blog

Neovim 0.5 Setup

2021-07-03

Neovim 0.5 is finally here! I am going to document some of my old notes that I took when I used nightly as well as some new stuff.

init.lua

You can use init.lua instead of init.vim to have your configuration file be written in lua! To be honest, I don't think there is a good reason to do this other than fighting boredom. I don't even think you can learn lua doing it. Here are some things that I learned from doing it. Replacing let is just using vim.g. Keymaps can be defined with vim.api.nvim_set_keymap(). Things you do with set you can do with vim.o. However, when I was setting my undodir using vim.o.undodir, I had to use vim.fn.expand because it took the ~/.vimundo string literally which created a ~ folder for each of my working directories. Therefore I had to use vim.o.undodir = vim.fn.expand '~/.vimundo'. There are probably other caveats as well. This is most definitely a bad introduction but there is now good documentation if you use :h lua-vimscript. The vim.api functions can be found under :h api.txt.

Plugins

Since the introduction of lua, there has been a lot of new plugins. I now use packer.nvim as my package manager as it supports lazy loading to improve startup time and you can configure your packages declaratively. A cool plugin that I discovered was telescope.nvim, but it was pretty slow for grepping files; I found snap but I haven't tried it. I also have been meaning to try out neogit.

Update on 2021-07-18: It looks like telescope is getting faster. There's also this cool list of plugins that I found.

LSP

With 0.5, neovim now has a builtin LSP client. Advantages over other LSP clients are customability and speed. If you are happy with your current setup, you don't really need to switch. When I was running nightly, I had to do a lot of special configuration, but I now think the builtin LSP is super easy to setup. Checkout nvim-lspconfig and its wiki and you should be good to go. Basically you need to install the language servers yourself (or use a plugin), and you need to setup completion (I used to use completion.nvim but I found nvim-compe better). Some completions need snippet support, so you need to install a plugin that supports it (I use vim-vsnip but might switch to lua-based one) and you also need tell the lsp server that you can use snippets by overriding the default client capabilities.

Treesitter

We also get introduced to the beta of treesitter support in neovim. It basically allows you to leverage an incremental parsing library. You can use it to manipulate your file based on the syntax trees parsed. You can also have better highlighting, indentation, and folding support. I currently only use treesitter for the better syntax highlighting, so I haven't really tried treesitter out. You do need to install a plugin however.