NvChad
Sources:
- NvChad
- NvChad --- Rocky Linux
- Dreams of Code's NvChad playlist
- BrunoKrugel's Github repo
Note: This article will only focus on NvChad itself. If you want to simply copy my computer configs (ALL OF THEM), you can refer to How to Set Up on A New Machine.
How to install
--> NvChad Installation Doc
Install NvChad
1
git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1 && nvim
Set environment variable in
~/.zshrc
for convience:1
export NVIM_CUSTOM_HOME="$DOT_FILE_HOME/nvchad_custom"
Install NvChad. Detete its default custom file. Use a symbol link, which is to my custom file in the dotfile, to replace it.
1
ln -s $NVIM_CUSTOM_HOME/ ~/.config/nvim/lua/custom
Components
Treesitter
Nvim-treesitter plugin is used to suport syntax highlighting in NvChad. It can be used for various things such as auto indent etc too.
For knowing correct parser names, do check nvim-treesitter docs
You can also get a list of all available languages and their installation status with
:TSInstallInfo
1
TSInstallInfo
To install parsers:
1
TSInstall <parser>
Example :
1 | TSInstall lua html |
But this may be tedious when you have so many parsers to install and you'd have to repeat this step if you're re-installing nvchad with your old custom settings.
Telescope
FInd finds in current peoject (aka directory):
1 | <leader> + ff |
FInd finds in current buffer:
1 | <leader> + fz |
FInd finds in all buffers:
1 | <leader> + fb |
Functionalitoes
Cheet sheet:
1
<Ctrl> + ch
Window Management
window --> buffer
tab --> buffer
Nagivate windows:
1
<Ctrl> + [hjkl]
Navigate tabs:
1
<Tab>
Close current buffer:
1
<leader> + x
Split windows:
1
:vsp
(vertical split)
Terminal
Open terminal horizontally:
1
<leader> + h
vertically
1
<leader> + v
LSP
neovim/nvim-lspconfig
In custom/plugins.lua
:
1 | -- In order to modify the `lspconfig` configuration: |
This controls the behavior of LSP.
The file plugins/configs/lspconfi.lua
is thr system config, we shouldn't change it. What we need to modify is custom/configs/lspconfig.lua
. We can see its content:
1 | local on_attach = require("plugins.configs.lspconfig").on_attach |
It's clear that the function for loop for _, lsp in ipairs(servers) do ... end
add the on_attach
and capabilities
attributes to every lsp server defined in the list servers
.
So if we have a new lsp server, it has to be added to the servers
list.
Mason.nvim
The mason.nvim plugin is used to install LSP servers, formatters, linters, and debug adapters.
Note: Packages are installed in Neovim's data directory (:h standard-path
) by default. In Unix, it's under ~/.local/share/nvim
You can mannualy install lsp packages using :Mason
, that will open a window.
However, It's better to list all your required packages in the config file so they automatically install when running MasonInstallAll
command.
As you can see in the custom/plugins.lua
:
1 | -- override plugin configs |
It reads the mason part of the override config file custom/configs/overrides.lua
:
1 | M.mason = { |
Format & Lint
It is recommended that you install null-ls
to manage formatting & linting. It hae s been installed as a dependency of neovim/nvim-lspconfig
.
1 | -- In "custom/plugins.lua" |
As before, if we want to customize, we need to modify file custom.configs.null-ls
.
DAP
All custimzation should be made in the custom
file.
There are 2 important files in custom dir which extend NvChad:
custom/chadrc.lua
meant to override that table indefault_config.lua
filecustom/init.lua
runs in the maininit.lua
, its meant to have vim options, globals, autocmds, commands etc.
The download of nvim-dap-ui
may be slow. If you didn't see the UI when debugging, please install this plugin mannually.
Customization
The config dir is ~/.config/nvim/lua
, with total structure
1 | . |
init.lua
- runs whole configcore/default_config
- returns a table of default options in NvChad.core/mappings
- default mappingscore/init
- default globals, nvim options, commands, autocmdscore/utils
- helpful functions
How to add LSP server
First, to install a lsp server, we need to add lsp config in the mason part of
custom/configs/overrides.lua
. For instance, we add a lsp server "pyright" to it.1
2
3
4
5
6
7
8
9M.mason = {
ensure_installed = {
-- Other servers
-- ....
-- python stuff
"pyright",
},
}Next, we need to add this server to the
servers
list incustom/configs/lspconfig.lua
. For instance, since we already have apyright
server, we add it in the list:1
2-- In "custom/configs/lspconfig.lua"
local servers = { "html", "cssls", "tsserver", "clangd", "pyright" }config this server so that it can apply to python files. In we h
Other Plugins
olimorris/persisted.nvim
Zeioth/compiler.nvim
akinsho/toggleterm.nvim
nvim-neotest/neotest
folke/noice.nvim
: colorful floating notice message
CPP
By default, clang-format is K&R style. You can change the format by putting a .clang-format
file in the project.
For instance, if you want to use Google clang style:
1 | clang-format --style Google --dump-config > .clang-format |
Then save and format.
Plugins
Project Manager
The following table shows all available operations
Key | Operation |
---|---|
<CR> |
Opens the project under the cursor |
<C-a> |
Adds a project through an interactive procedure |
<C-d> |
Delete a project |
<C-e> |
Change project settings |
<C-q> |
Close buffer |
To add your first project you will need to use the combination Ctrl + a which will open an interactive menu in the statusline.
Run
<leader> + db
<leader> + dr
Don't need to <leader> +dus
Rust
1 | RustDebuggales |