Mappings
- list of some important mappings!
- C = Ctrl
- leader = space
- A = alt
- S = shift
Navigate in insert mode
C + h/j/k/l
- move cursorC + a
- beginning of the lineC + e
- end of the line
Switch windows
C + h
- switch left windowC + j
- switch bottom windowC + k
- switch top windowC + l
- switch right window
Misc
C + s
- saveS + b
- new bufferleader + n
- toggle number lineleader + rn
- toggle relative number line
NvChad
leader + uu
- update nvchadleader + th
- change themes
Terminal
A + i
- toggle floating terminalA + h
- toggle horizontal terminalA + v
- toggle vertical terminalleader + h
- new horizontal terminalleader + v
- new vertical terminal
NvimTree
C + n
- toggle NvimTree
(Note check the rest of the mappings by running :Telescope keymaps)
Customization
- Defaults are defined in
core.mappings
(core/mappings.lua), which you should familiarize yourself with - User mappings should be defined in the
mappings
field of the table returned bycustom.chadrc
(these can be required from another file, e.g.,M.mappings = require "custom.mappings"
)
Mapping format
-- general format
-- opts here is completely optional
["keys"] = {"action", "icon mapping description", opts = {}},
["keys"] = {"action", opts = {}}, -- non whichkey users
-- examples
["<C-n>"] = {"<cmd> NvimTreeToggle <CR>", "Toggle nvimtree", opts = {}},
["<C-s>"] = { "<cmd> w <CR>", " save file" },
["<leader>uu"] = { "<cmd> :NvChadUpdate <CR>", " update nvchad" },
-- example with lua function
["<leader>tt"] = {
function()
require("base46").toggle_theme()
end,
" toggle theme",
},
- The mapping description is required for
WhichKey
but this can be disabled - As shown above, you can use lua functions in the mappings (e.g., to call lua modules)
- Icons are visually appealing and help readability, but they are optional
- Best practice: place icons before the textual description, separated by 2-3 spaces
- Tip: Find icons to copy/paste at https://www.nerdfonts.com/cheat-sheet
Default opts values
{
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
silent = true,
noremap = true,
nowait = false,
-- all standard key binding opts are supported
}
- Note : This is completely optional
Mappings table structure
- This is the mappings structure of core.mappings and your mappings file
local M = {}
-- add this table only when you want to disable default keys
M.disabled = {
n = {
["<leader>h"] = "",
["<C-s>"] = ""
}
}
M.abc = {
n = {
["<C-n>"] = {"<cmd> Telescope <CR>", "Open Telescope"}
}
-- non which key users
n = {
["<C-n>"] = {"<cmd> Telescope <CR>"}
}
i = {
-- more keys!
}
}
M.xyz = {
-- stuff
}
return M
abc
andxyz
above are arbitrary; they could, for example, be a plugin’s name- n, i, v, are the mode names, i.e., normal, insert, visual
- Be sure to maintain a table structure similar to core.mappings
Override default mappings & create mappings
- lets override nvimtree’s mappings
-- chadrc
M.mappings = require "custom.mappings"
-- the above path can be any file in custom dir, just an example!
-- custom.mappings
local M = {}
M.nvimtree = {
n = {
["<leader>ff"] = { "<cmd> NvimTreeToggle <CR>", " toggle nvimtree" },
["<C-n>"] = { "<cmd> Telescope <CR>", "open telescope" },
},
}
- Check siduck’s config for reference
- The same way you can add your mappings :)
Mapping with which-key disabled
- The method’s just the same but in this you dont have to write the mappings description!
- Also put this into your custom.init.lua file :
require("core.utils").load_mappings()