LSP Support in Neovim
created: 2025-04-19 05:23:48 UTClast updated: 2025-04-19 05:24:58 UTC
To start this off, first let me say this. I have been an emacs user for awhile. However, around the start of the C++ variant of this, I decided to give vim's younger sibling a try. Well more specifically, a distribution of Neovim called Lunarvim. Using a pre-baked distribution is actually how I got started with emacs. I was using spacemacs initially, and then went into doing my own small vanilla config. Learning that Neovim has distributions, I decided to give that a shot and ended up on choosing Lunarvim. So far, it has worked out well. Takes a lot of getting used to as on emacs, I used the original emacs keybindings and not the evil mode. Getting used to modal editing is taking a bit, and to be fair, I'm still not very good at it.
One thing that is nice though is how much easier, at least the Neovim distributions, make setting up some things in LSP. The big one is projects with the LSP config. I also learned a few new things. First, CMake can generate the compile_commands.json file. This can be easily done with the addition of one line in the CMakeLists.txt file.
# compile commands output for lsp set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Lastly to get the LSP working well with C++ in the project directory, just need to make a change in the Lua config.
lvim.lsp.automatic_configuration.skipped_servers = { "clangd", } local lspconfig = require("lspconfig") lspconfig.clangd.setup({ cmd = { "clangd", "--compile-commands-dir=build" }, root_dir = lspconfig.util.root_pattern("compile_commands.json", "compile_flags.txt", ".git"), })
After opening up lunar vim in the project directory and initializing the build directory with CMake, the LSP in Lunarvim picks everything up just fine.
Recently, Ive been dabbling on something else a little bit, but I am getting back to this. Currently doing some major refactor. Once that is complete, I plan to post about that.