Mappings

  • list of some important mappings!
  • C = Ctrl
  • leader = space
  • A = alt
  • S = shift

Navigate in insert mode

  • C + h/j/k/l - move cursor
  • C + a - beginning of the line
  • C + e - end of the line

Switch windows

  • C + h - switch left window
  • C + j - switch bottom window
  • C + k - switch top window
  • C + l - switch right window

Misc

  • C + s - save
  • S + b - new buffer
  • leader + n - toggle number line
  • leader + rn - toggle relative number line

NvChad

  • leader + uu - update nvchad
  • leader + th - change themes

Terminal

  • A + i - toggle floating terminal
  • A + h - toggle horizontal terminal
  • A + v - toggle vertical terminal
  • leader + h - new horizontal terminal
  • leader + 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 by custom.chadrc (these can be required from another file, e.g., M.mappings = require "custom.mappings")

Mapping format

  1. -- general format
  2. -- opts here is completely optional
  3. ["keys"] = {"action", "icon mapping description", opts = {}},
  4. ["keys"] = {"action", opts = {}}, -- non whichkey users
  5. -- examples
  6. ["<C-n>"] = {"<cmd> NvimTreeToggle <CR>", "Toggle nvimtree", opts = {}},
  7. ["<C-s>"] = { "<cmd> w <CR>", "﬚ save file" },
  8. ["<leader>uu"] = { "<cmd> :NvChadUpdate <CR>", " update nvchad" },
  9. -- example with lua function
  10. ["<leader>tt"] = {
  11. function()
  12. require("base46").toggle_theme()
  13. end,
  14. " toggle theme",
  15. },

Default opts values

  1. {
  2. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  3. silent = true,
  4. noremap = true,
  5. nowait = false,
  6. -- all standard key binding opts are supported
  7. }
  • Note : This is completely optional

Mappings table structure

  • This is the mappings structure of core.mappings and your mappings file
  1. local M = {}
  2. -- add this table only when you want to disable default keys
  3. M.disabled = {
  4. n = {
  5. ["<leader>h"] = "",
  6. ["<C-s>"] = ""
  7. }
  8. }
  9. M.abc = {
  10. n = {
  11. ["<C-n>"] = {"<cmd> Telescope <CR>", "Open Telescope"}
  12. }
  13. -- non which key users
  14. n = {
  15. ["<C-n>"] = {"<cmd> Telescope <CR>"}
  16. }
  17. i = {
  18. -- more keys!
  19. }
  20. }
  21. M.xyz = {
  22. -- stuff
  23. }
  24. return M
  • abc and xyz 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
  1. -- chadrc
  2. M.mappings = require "custom.mappings"
  3. -- the above path can be any file in custom dir, just an example!
  1. -- custom.mappings
  2. local M = {}
  3. M.nvimtree = {
  4. n = {
  5. ["<leader>ff"] = { "<cmd> NvimTreeToggle <CR>", " toggle nvimtree" },
  6. ["<C-n>"] = { "<cmd> Telescope <CR>", "open telescope" },
  7. },
  8. }

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 :
  1. require("core.utils").load_mappings()