Skip to content

Instantly share code, notes, and snippets.

@hjwp
Created December 21, 2023 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjwp/80853447ca40d1a92d29d5ab313a3920 to your computer and use it in GitHub Desktop.
Save hjwp/80853447ca40d1a92d29d5ab313a3920 to your computer and use it in GitHub Desktop.
new (neo) vim config from scratch, in lua, write-up.

Thought I'd provide a few more details in case anyone else fancies taking the plunge into neovim / lua-only config / declaring vim-bankruptcy on their current config and starting from scratch.

Objectives

My key objectives were:

  • keepings some, but not necessarily all, of my vim settings + custom keymaps
  • LSP features, specifically
    • autocompletion
    • jump-to-definition
    • and any other well-supported LSP features that work ok for Python
  • linting (including support for non-LSP-based linters)
  • fuzzy file finder.

I was inspired by this Primagean video called Zero to LSP from scratch in which he sets up a new lua/neovim config from scratch in about 20 minutes. This was my second go at setting up nvim, so i did start with some background

Config approach

People seem to keep their neovim config in lots of different files but that freaked me out. I decided to go with a single file. The challenge there is that some bits of config are time or context dependent, particularly if you're using lazy.nvim as your package manager - you only want to set certain options if a particular plugin has (a) loaded and (b) been activated. I decided to go for a very javascriptey "nested callbacks" sort of approach, which is kinda ugly but at leat everything is in one file and all the dependencies are explicit.

Config + Key Plugins

I used lazy.nvim as my plugin manager because one of the tutorials suggested it was what the cool kids are using and I want to be cool. Something-something lazy-loading apparently?

  • The main one is lsp-zero which is a wrapper around several LSP plugins. It includes a thing called Mason, which auto-installs and configures language servers on demand, and another library called cmp that does autocompletion.

    • --> That gave me autocompletion, jump-to-definition, and several linters/diagnostics out of the box
    • and now whenever I open a new file type I have the option of downloading LSPs for it, from a list of suggested ones.
  • I had to add some custom configuration for a generic LSP-based linter-wrapper called efm-langserver which essentially lets you run "normal" linters but using an LSP interface to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment