🧠 Second Brain

Search

Search IconIcon to open search

Neovim Setup

Last updated Feb 18, 2024

# VS Code style

See Neovim set up like VS Code.

# Nvim Setup

Latest with Lazy.nvim even:
How I Setup LSP In Neovim For An Amazing Dev Experience - Full Guide - YouTube

# LSP with lazy.nvim

I was struggling a lot to set up LSP with lazy.nvim. There was the nvim-lspconfig, the nvim-cmp (for pop-up window), mason.nvim for easy install, and none-ls (previously null-ls).

I had lsp-zero in my old config, and in lazy.nvim, I tried several setups to put it in different config = function() blocks.

As I might guess, others are struggling too, the video and especially the dotfiles from Josean Martinez just solved it for me. I saw he skipped lsp-zero with lazy and I could understand how to set up.

I ended up copying his setup and just replacing it with my shortcuts and configs. Here are the most important parts which were important to me.

# LSP Setup

Add an lsp folder to lazy.lua (replace josean with your name)

1
require("lazy").setup({ { import = "josean.plugins" }, { import = "josean.plugins.lsp" } }, {
  1. Add a nvim-cmp.lua for proper auto-compmlete, see dev-environment-files/.config/nvim/lua/josean/plugins/nvim-cmp.lua at main · josean-dev/dev-environment-files · GitHub
  2. Copy his lsp folder and check what he is doing. notice there is no lsp-zero (not sure if that can still be used?)
    1. I enjoy that in lspconfig.lua, he configures, each language server is configured manually, as this gives a sense of control that I missed before when I just assumed it would work (but probably didn’t all the time).
    2. ensure_installed with the installed packages you want can be configured easily in mason.lua
    3. and setting for linting can be set in one place under none-ls.lua .

After I copied his configs and commented out mine, it just worked. So I could simply replace his shortcuts and configs with mine, and it just worked, and my frustration went back to joy. I have no agenda to promote his content, but just to help others who might struggle too.

# Speed update

Also, a nice side effect: my startup time (Vim StartUp Times) went through the roof and starts now in 76 ms, even with 82 plugins 🙈. I hope that helps; my LSP configs I ended up with can be found in my dotfiles, too.

One thing I couldn’t figure out was the format on save; didn’t work for me in Python. I had this before that worked:

1
2
3
4
5
6
7
Show autodiagnostic popup on cursor hover_range
vim.cmd([[
" Python: auto format on save with Black
autocmd BufWritePre *.py execute ':Black'
" set virtual env -> still needed with lsp? 
let g:python3_host_prog = expand($HOME."/.venvs/nvim/bin/python3")
]])

But I was hoping to include it in the none-ls.lua in on_attach function. If anyone has a hint, it would be super appreciated.


Origin:
References:
Created 2024-02-18