rookiemistake

How I moved my setup to Neovim #2

Two weeks to go from a full IDE to a terminal editor configured in Lua.

Published2 min read248 words
Contents

For years I used a full IDE. It worked, but every update brought a few broken plugins and a handful of extra seconds at startup. I decided to try Neovim for a whole month, with no going back.

The configuration layout

I kept everything in a single folder, split by responsibility:

~/.config/nvim
init.lua
lua/
  core/
    options.lua
    keymaps.lua
  plugins/
    lsp.lua
    telescope.lua
    treesitter.lua

The entry file only loads the modules:

init.lua
vim.g.mapleader = " "
 
require("core.options")
require("core.keymaps")
 
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.rtp:prepend(lazypath)
 
require("lazy").setup("plugins")

The options that actually matter

Of all the options I tried, these are the ones I kept:

lua/core/options.lua
local opt = vim.opt
 
opt.number = true
opt.relativenumber = true
opt.signcolumn = "yes"
opt.expandtab = true
opt.shiftwidth = 2
opt.scrolloff = 8
opt.undofile = true

The highlighted lines are the ones that stopped me from losing the cursor: relative numbers and an always-visible sign column, so the text does not "jump" when an error appears.

LSP without losing your mind

The part I feared most turned out to be the simplest. With the built-in LSP client, a few lines per language are enough:

lua/plugins/lsp.lua
return {
  "neovim/nvim-lspconfig",
  config = function()
    vim.lsp.enable({ "ts_ls", "lua_ls", "rust_analyzer" })
 
    vim.api.nvim_create_autocmd("LspAttach", {
      callback = function(event)
        local map = function(keys, fn)
          vim.keymap.set("n", keys, fn, { buffer = event.buf })
        end
        map("gd", vim.lsp.buf.definition)
        map("K", vim.lsp.buf.hover)
        map("<leader>rn", vim.lsp.buf.rename)
      end,
    })
  end,
}

What I miss

Honestly, very little. The visual debugger is the only thing I still open the IDE for now and then. For everything else, nvim . and off I go.