NvChad/lua/nvchad/mappings.lua

128 lines
4.8 KiB
Lua
Raw Normal View History

2024-02-25 03:13:48 +00:00
local map = vim.keymap.set
map("i", "<C-b>", "<ESC>^i", { desc = "move beginning of line" })
map("i", "<C-e>", "<End>", { desc = "move end of line" })
map("i", "<C-h>", "<Left>", { desc = "move left" })
map("i", "<C-l>", "<Right>", { desc = "move right" })
map("i", "<C-j>", "<Down>", { desc = "move down" })
map("i", "<C-k>", "<Up>", { desc = "move up" })
2024-02-27 14:07:57 +00:00
map("n", "<Esc>", "<cmd>noh<CR>", { desc = "general clear highlights" })
2024-02-27 14:07:57 +00:00
map("n", "<C-h>", "<C-w>h", { desc = "switch window left" })
map("n", "<C-l>", "<C-w>l", { desc = "switch window right" })
map("n", "<C-j>", "<C-w>j", { desc = "switch window down" })
map("n", "<C-k>", "<C-w>k", { desc = "switch window up" })
2024-02-27 14:07:57 +00:00
map("n", "<C-s>", "<cmd>w<CR>", { desc = "file save" })
map("n", "<C-c>", "<cmd>%y+<CR>", { desc = "file copy whole" })
2024-02-27 14:07:57 +00:00
map("n", "<leader>n", "<cmd>set nu!<CR>", { desc = "toggle line number" })
map("n", "<leader>rn", "<cmd>set rnu!<CR>", { desc = "toggle relative number" })
map("n", "<leader>ch", "<cmd>NvCheatsheet<CR>", { desc = "toggle nvcheatsheet" })
2024-02-25 03:13:48 +00:00
map("n", "<leader>fm", function()
2024-03-18 00:59:28 +00:00
require("conform").format { lsp_fallback = true }
end, { desc = "format files" })
2024-02-25 03:13:48 +00:00
2024-03-18 00:59:28 +00:00
-- global lsp mappings
map("n", "<leader>ds", vim.diagnostic.setloclist, { desc = "lsp diagnostic loclist" })
2024-02-27 07:01:36 +00:00
-- tabufline
map("n", "<leader>b", "<cmd>enew<CR>", { desc = "buffer new" })
2024-02-27 14:07:57 +00:00
2024-02-27 07:01:36 +00:00
map("n", "<tab>", function()
2024-03-04 02:37:10 +00:00
require("nvchad.tabufline").next()
end, { desc = "buffer goto next" })
2024-02-27 07:01:36 +00:00
map("n", "<S-tab>", function()
2024-03-04 02:37:10 +00:00
require("nvchad.tabufline").prev()
end, { desc = "buffer goto prev" })
2024-02-27 07:01:36 +00:00
map("n", "<leader>x", function()
require("nvchad.tabufline").close_buffer()
end, { desc = "buffer close" })
2024-02-27 07:01:36 +00:00
2024-02-27 14:07:57 +00:00
-- Comment
2024-02-27 07:01:36 +00:00
map("n", "<leader>/", function()
require("Comment.api").toggle.linewise.current()
end, { desc = "comment toggle" })
2024-02-27 07:01:36 +00:00
map(
"v",
"<leader>/",
"<ESC><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<CR>",
{ desc = "comment toggle" }
2024-02-27 07:01:36 +00:00
)
2024-02-27 14:07:57 +00:00
-- nvimtree
map("n", "<C-n>", "<cmd>NvimTreeToggle<CR>", { desc = "nvimtree toggle window" })
map("n", "<leader>e", "<cmd>NvimTreeFocus<CR>", { desc = "nvimtree focus window" })
2024-02-27 14:07:57 +00:00
-- telescope
map("n", "<leader>fw", "<cmd>Telescope live_grep<CR>", { desc = "telescope live grep" })
map("n", "<leader>fb", "<cmd>Telescope buffers<CR>", { desc = "telescope find buffers" })
map("n", "<leader>fh", "<cmd>Telescope help_tags<CR>", { desc = "telescope help page" })
map("n", "<leader>ma", "<cmd>Telescope marks<CR>", { desc = "telescope find marks" })
map("n", "<leader>fo", "<cmd>Telescope oldfiles<CR>", { desc = "telescope find oldfiles" })
map("n", "<leader>fz", "<cmd>Telescope current_buffer_fuzzy_find<CR>", { desc = "telescope find in current buffer" })
map("n", "<leader>cm", "<cmd>Telescope git_commits<CR>", { desc = "telescope git commits" })
map("n", "<leader>gt", "<cmd>Telescope git_status<CR>", { desc = "telescope git status" })
map("n", "<leader>pt", "<cmd>Telescope terms<CR>", { desc = "telescope pick hidden term" })
map("n", "<leader>th", "<cmd>Telescope themes<CR>", { desc = "telescope nvchad themes" })
map("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "telescope find files" })
2024-02-25 03:13:48 +00:00
map(
2024-02-27 07:01:36 +00:00
"n",
"<leader>fa",
"<cmd>Telescope find_files follow=true no_ignore=true hidden=true<CR>",
{ desc = "telescope find all files" }
2024-02-25 03:13:48 +00:00
)
2024-02-27 07:01:36 +00:00
-- terminal
map("t", "<C-x>", "<C-\\><C-N>", { desc = "terminal escape terminal mode" })
2024-02-27 14:07:57 +00:00
2024-03-08 14:16:31 +00:00
-- new terminals
2024-02-27 07:01:36 +00:00
map("n", "<leader>h", function()
require("nvchad.term").new { pos = "sp" }
end, { desc = "terminal new horizontal term" })
2024-02-27 07:01:36 +00:00
map("n", "<leader>v", function()
require("nvchad.term").new { pos = "vsp" }
end, { desc = "terminal new vertical window" })
2024-02-27 07:01:36 +00:00
2024-03-08 14:16:31 +00:00
-- toggleable
2024-02-27 07:01:36 +00:00
map({ "n", "t" }, "<A-v>", function()
require("nvchad.term").toggle { pos = "vsp", id = "vtoggleTerm" }
end, { desc = "terminal toggleable vertical term" })
2024-02-27 07:01:36 +00:00
map({ "n", "t" }, "<A-h>", function()
require("nvchad.term").toggle { pos = "sp", id = "htoggleTerm" }
end, { desc = "terminal new horizontal term" })
2024-02-27 07:01:36 +00:00
map({ "n", "t" }, "<A-i>", function()
require("nvchad.term").toggle { pos = "float", id = "floatTerm" }
end, { desc = "terminal toggle floating term" })
2024-02-27 07:01:36 +00:00
-- whichkey
map("n", "<leader>wK", "<cmd>WhichKey <CR>", { desc = "whichkey all keymaps" })
2024-02-27 14:07:57 +00:00
2024-02-27 07:01:36 +00:00
map("n", "<leader>wk", function()
vim.cmd("WhichKey " .. vim.fn.input "WhichKey: ")
end, { desc = "whichkey query lookup" })
2024-02-27 07:01:36 +00:00
2024-02-27 14:07:57 +00:00
-- blankline
2024-02-27 07:01:36 +00:00
map("n", "<leader>cc", function()
local config = { scope = {} }
config.scope.exclude = { language = {}, node_type = {} }
config.scope.include = { node_type = {} }
local node = require("ibl.scope").get(vim.api.nvim_get_current_buf(), config)
if node then
local start_row, _, end_row, _ = node:range()
if start_row ~= end_row then
vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start_row + 1, 0 })
vim.api.nvim_feedkeys("_", "n", true)
2024-02-25 03:13:48 +00:00
end
2024-02-27 07:01:36 +00:00
end
end, { desc = "blankline jump to current context" })