26 lines
1.2 KiB
Lua

local map = vim.keymap.set
-- Normal mode
map("n", "<C-n>", "<cmd>enew<cr>", { desc = "New File" })
map("n", "<C-b>", "<cmd>NvimTreeToggle<cr>", { desc = "Toggle file explorer" })
map("n", "<C-q>", "<cmd>qa<cr>", { desc = "Quit all" })
map("n", "<leader>l", "<cmd>Lazy<cr>", { desc = "Lazy" })
map("n", "<leader>f", "<cmd>Telescope find_files<cr>", { desc = "Find files" })
map("n", "<leader>r", "<cmd>Telescope oldfiles<cr>", { desc = "Recent files" })
map("n", "<leader>s", "<cmd>Telescope symbols<cr>", { desc = "Symbols" })
map("n", "<leader>cf", vim.lsp.buf.format, { desc = "Format" })
map("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition" })
map("n", "gr", vim.lsp.buf.references, { desc = "Go to references" })
-- Visual mode
map("v", "<", "<gv")
map("v", ">", ">gv")
-- Mixed modes
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Clear search" })
map({ "i", "v", "n", "s" }, "<C-s>", "<cmd>w<cr><esc>", { desc = "Save file" })
-- Toggle comment
map("n", "<leader>/", "<cmd>lua require('Comment.api').toggle.linewise.current()<cr>", { desc = "Toggle comment" })
map("v", "<leader>/", "<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>", { desc = "Toggle comment" })