In this fifth installment of our Neovim series, we implement automatic code formatting using conform.nvim - a powerful plugin that integrates with both dedicated formatters and our previously configured LSP servers.
I'll guide you through setting up conform.nvim to automatically select the right formatter based on file type, with intelligent fallbacks that prioritize dedicated formatters but use LSP formatting when needed. We'll create autocommands that trigger formatting whenever you save a file, eliminating manual formatting steps and ensuring consistently styled code with zero effort.
By the end, your Neovim setup will automatically handle code formatting across your entire technology stack, bringing another professional IDE feature into your customized environment while maintaining the speed and flexibility that makes Neovim so powerful.
All configuration files demonstrated in this episode are available on GitHub: https://github.com/jakobwesthoff/nvim-from-scratch/tree/session/05
Chapters:
00:00 - Introduction
02:11 - Install conform.nvim
03:36 - Configure conform.nvim
08:35 - Calling conform.format()
09:58 - Using a Keybinding for Formatting
11:56 - Format on Save
15:00 - Fallback on LSP for Formatting
16:23 - Checking for installed Formatters
18:00 - Installing Formatters
22:09 - Use the auto installed prettierd
24:02 - Adding a new language to be formatted
25:04 - LSP as a Fallback in Action
28:01 - Project based Formatter Configuration
29:08 - Excursion: Display Hidden Files with oil.nvim
30:08 - Back to: Project based Formatter Configuration
31:46 - Future Outlook