home ~ projects ~ socials

Setup Auto-Formatting For C++ Files In Neovim On A Mac

Turns out all I had to do was uncomment clangd = {} in the local servers section of my ~/.config/nvim/init.lua file to turn on the clangd LSP. (I already had clangd installed)

I think the LSP config with the commented out clangd server was from the kickstart.nvimks config file I'm using.

These are scratchpad notes I took while figuring things out. Leaving them here as reference.

Notes

  • Installed clang-format with:

    brew install clang-format

  • Video with clangd instead of clang-format

    https://www.youtube.com/watch?v=BCuyEdDQ5iA

    this vid uses nvim-lspconfig which I already had installed

  • clangd installation

    https://clangd.llvm.org/installation.html

    (I already had it installed)

Reference Links To Add

Notes

  • https://github.com/neovim/nvim-lspconfig
  • https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion
  • https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#clangd
  • https://github.com/nvim-lua/kickstart.nvim/blob/master/lua/kickstart/plugins/autoformat.lua
  • https://www.youtube.com/watch?v=BCuyEdDQ5iA
  • https://clangd.llvm.org/installation.html
  • https://github.com/sbdchd/neoformat (not what i ended up with but it was referenced a few times)
  • https://jdhao.github.io/2020/04/19/nvim_cpp_and_c_completion/ - another appraoch with different tools. This is what I was looking at first, but when I figured out I could use the LSP I went that direction
  • https://www.reddit.com/r/vim/comments/s5zjd5/formatter_for_c_code_in_neovim/ pointers to some built-in help files for formatting, but not super useful and it doesn't use the LSP
-- end of line --

References

I got turned onto this from TJ DeVries who works on Neovim. It's worked well as a basic starter for me.

This is the post that got me started. It has instruction for auto-completion as well as formatting. I'll get to that at some point, but my immediate concern is the formatting.