nvim/lua/user/keymaps.lua

108 lines
4 KiB
Lua
Raw Normal View History

2022-10-12 22:07:20 -04:00
-- Shorten function name
local keymap = vim.keymap.set
-- Silent keymap option
local opts = { silent = true }
--Remap space as leader key
keymap("", "<Space>", "<Nop>", opts)
vim.g.mapleader = " "
-- Modes
-- normal_mode = "n",
-- insert_mode = "i",
-- visual_mode = "v",
-- visual_block_mode = "x",
-- term_mode = "t",
-- command_mode = "c",
-- Normal --
-- Better window navigation
keymap("n", "<C-h>", "<C-w>h", opts)
keymap("n", "<C-j>", "<C-w>j", opts)
keymap("n", "<C-k>", "<C-w>k", opts)
keymap("n", "<C-l>", "<C-w>l", opts)
-- Resize with arrows
keymap("n", "<C-Up>", ":resize -2<CR>", opts)
keymap("n", "<C-Down>", ":resize +2<CR>", opts)
keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts)
keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts)
-- Navigate buffers
keymap("n", "<S-l>", ":bnext<CR>", opts)
keymap("n", "<S-h>", ":bprevious<CR>", opts)
2022-10-14 17:19:21 -04:00
for _, mode in ipairs({"n", "i", "v"}) do
vim.keymap.set(mode, '<A-1>', "<Cmd>BufferLineGoToBuffer 1<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, '<A-2>', "<Cmd>BufferLineGoToBuffer 2<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, '<A-3>', "<Cmd>BufferLineGoToBuffer 3<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, '<A-4>', "<Cmd>BufferLineGoToBuffer 4<CR>", { noremap = true, silent = true })
vim.keymap.set(mode, '<A-5>', "<Cmd>BufferLineGoToBuffer 5<CR>", { noremap = true, silent = true })
end
2022-10-12 22:07:20 -04:00
-- Clear highlights
keymap("n", "<leader>h", "<cmd>nohlsearch<CR>", opts)
-- Close buffers
2022-10-14 17:19:21 -04:00
keymap("n", "<S-q>", "<cmd>Bdelete<CR>", opts)
2022-10-16 14:18:21 -04:00
keymap("n", "<S-q>", "<cmd>Bdelete!<CR>", opts)
2022-10-12 22:07:20 -04:00
-- Better paste
keymap("v", "p", '"_dP', opts)
-- Insert --
-- Press jk fast to enter
2022-10-14 17:19:21 -04:00
--keymap("i", "jk", "<ESC>", opts)
2022-10-12 22:07:20 -04:00
-- Visual --
-- Stay in indent mode
keymap("v", "<", "<gv", opts)
keymap("v", ">", ">gv", opts)
-- Plugins --
-- NvimTree
keymap("n", "<leader>e", ":NvimTreeToggle<CR>", opts)
-- Telescope
keymap("n", "<leader>ff", ":Telescope find_files<CR>", opts)
keymap("n", "<leader>ft", ":Telescope live_grep<CR>", opts)
keymap("n", "<leader>fp", ":Telescope projects<CR>", opts)
keymap("n", "<leader>fb", ":Telescope buffers<CR>", opts)
-- Git
2022-10-14 17:19:21 -04:00
--keymap("n", "<leader>gg", "<cmd>lua _LAZYGIT_TOGGLE()<CR>", opts)
2022-10-12 22:07:20 -04:00
-- Comment
keymap("n", "<leader>/", "<cmd>lua require('Comment.api').toggle_current_linewise()<CR>", opts)
keymap("x", "<leader>/", '<ESC><CMD>lua require("Comment.api").toggle_linewise_op(vim.fn.visualmode())<CR>')
2022-10-16 14:18:21 -04:00
---- DAP
--keymap("n", "<F9>", "<cmd>lua require'dap'.toggle_breakpoint()<cr>", opts)
--keymap("n", "<F5>", "<cmd>lua require'dap'.continue()<cr>", opts)
--keymap("n", "<F10>", "<cmd>lua require'dap'.step_over()<cr>", opts)
--keymap("n", "<F11>", "<cmd>lua require'dap'.step_into()<cr>", opts)
--keymap("n", "<F23>", "<cmd>lua require'dap'.step_out()<cr>", opts)
--keymap("n", "<leader>dr", "<cmd>lua require'dap'.repl.toggle()<cr>", opts)
--keymap("n", "<leader>dl", "<cmd>lua require'dap'.run_last()<cr>", opts)
--keymap("n", "<leader>du", "<cmd>lua require'dapui'.toggle()<cr>", opts)
--keymap("n", "<F17>", "<cmd>lua require'dap'.terminate()<cr>", opts)
-- Vimspector
keymap("n", "<F9>", "<Plug>VimspectorToggleBreakpoint", opts)
keymap("n", "<F5>", "<plug>VimspectorContinue", opts)
keymap("n", "<F10>", "<Plug>VimspectorStepOver", opts)
keymap("n", "<F11>", "<Plug>VimspectorStepInto", opts)
keymap("n", "<F23>", "<Plug>VimspectorStepOut", opts)
keymap("n", "<F17>", "<cmd>VimspectorReset<cr>", opts) -- Shift+F5
keymap("n", "<F41>", "<Plug>VimspectorRestart", opts) -- Ctrl+Shift+F5
keymap("n", "<leader>di", "<Plug>VimspectorBalloonEval", opts)
--keymap("n", "<leader>dl", "<cmd>lua require'dap'.run_last()<cr>", opts)
--keymap("n", "<leader>du", "<cmd>lua require'dapui'.toggle()<cr>", opts)
--keymap("n", "<F17>", "<cmd>lua require'dap'.terminate()<cr>", opts)
2022-10-18 13:05:39 -04:00
keymap("n", "<leader>lf", vim.lsp.buf.format, opts) -- Shift+F5
keymap("v", "<leader>lf", "<esc><cmd>'<,'>lua vim.lsp.buf.format()<cr>", opts) -- Shift+F5
keymap("x", "<leader>lf", "<esc><cmd>'<,'>lua vim.lsp.buf.format()<cr>", opts) -- Shift+F5