1
0
Fork 0
dotfiles/.config/nvim/lua/config/keymaps.lua

749 lines
17 KiB
Lua

local M = {}
local f = require("funcs")
local icons = require("config.icons")
local maps = f.empty_map_table()
M.sections = {
p = { desc = icons.Package .. " Packages" },
b = { desc = icons.Buffer .. " Buffers" },
bs = { desc = "Sort Buffers" },
d = { desc = icons.Bug .. " Debugger" },
g = { desc = icons.Git .. " Git" },
f = { desc = icons.Search .. " Find" },
l = { desc = icons.Code .. " LSP" },
t = { desc = icons.Console .. " Terminal" },
u = { desc = icons.Gear .. " Utility" },
n = { desc = icons.Note .. " Notes" },
e = { desc = icons.FileTree .. " File Manager" },
}
-- Standard --
maps.n["j"] = { "v:count == 0 ? 'gj' : 'j'", expr = true, desc = "Move cursor down" }
maps.n["k"] = { "v:count == 0 ? 'gk' : 'k'", expr = true, desc = "Move cursor up" }
maps.n["<Leader>w"] = { "<Cmd>w<CR>", desc = "Write buffer" }
maps.n["<Leader>c"] = { "<Cmd>conf q<CR>", desc = "Quit" }
maps.n["<Leader>C"] = { "<Cmd>conf qa<CR>", desc = "Quit all" }
maps.n["<Leader>n"] = { "<Cmd>ene<CR>", desc = "New buffer" }
maps.n["<Leader>h"] = { "<Cmd>noh<CR>", desc = "Clear highlight" }
maps.n["<C-s>"] = { "<Cmd>w!<cr>", desc = "Force write buffer" }
maps.n["<C-q>"] = { "<Cmd>qa!<cr>", desc = "Force quit all" }
maps.n["<Leader>|"] = { "<Cmd>vsplit<cr>", desc = "Vertical split" }
maps.n["<Leader>\\"] = { "<Cmd>split<cr>", desc = "Horizontal split" }
maps.v["<"] = { "<gv", desc = "Unindent line" }
maps.v[">"] = { ">gv", desc = "Indent line" }
maps.n["<Leader>q"] = { f.buf_close, desc = "Close buffer" }
maps.n["<C-b>"] = { "<C-a>" }
maps.n["<C-f>"] = { "<Nop>" }
maps.i["<C-h>"] = { "<C-W>" }
-- Utility --
if f.is_available("nvim-colorizer.lua") then
maps.n["<Leader>u"] = M.sections.u
maps.n["<Leader>uc"] = { "<Cmd>ColorizerToggle<CR>", desc = "Toggle colorizer" }
end
-- Notes --
if f.is_available("zk-nvim") then
maps.n["<Leader>n"] = M.sections.n
maps.v["<Leader>n"] = maps.n["<Leader>n"]
maps.n["<Leader>nn"] = {
function()
require("zk").new({ notebook_path = vim.g.wikidir, title = vim.fn.input("Title: ") })
end,
desc = "New Note",
}
maps.v["<Leader>nnt"] = {
":ZkNewFromTitleSelection { notebook_path = vim.g.wikidir }<CR>",
desc = "New Note (Selection as title)",
}
maps.v["<Leader>nnc"] = {
":ZkNewFromContentSelection { notebook_path = vim.g.wikidir, title = vim.fn.input('Title: ') }<CR>",
desc = "New Note (Selection as content)",
}
maps.n["<Leader>no"] = {
function()
require("zk").edit({ notebook_path = vim.g.wikidir })
end,
desc = "Open Note",
}
maps.n["<Leader>ni"] = {
function()
require("zk").index({ notebook_path = vim.g.wikidir })
end,
desc = "Index Notes",
}
end
-- Window Navigation --
maps.n["<C-h>"] = { "<C-w>h", desc = "Move to left split" }
maps.n["<C-j>"] = { "<C-w>j", desc = "Move to below split" }
maps.n["<C-k>"] = { "<C-w>k", desc = "Move to above split" }
maps.n["<C-l>"] = { "<C-w>l", desc = "Move to right split" }
maps.n["<C-Up>"] = { "<Cmd>resize -2<CR>", desc = "Resize split up" }
maps.n["<C-Down>"] = { "<Cmd>resize +2<CR>", desc = "Resize split down" }
maps.n["<C-Left>"] = { "<Cmd>vertical resize -2<CR>", desc = "Resize split left" }
maps.n["<C-Right>"] = { "<Cmd>vertical resize +2<CR>", desc = "Resize split right" }
maps.t["<C-h>"] = { "<Cmd>wincmd h<cr>", desc = "Terminal left window navigation" }
maps.t["<C-j>"] = { "<Cmd>wincmd j<cr>", desc = "Terminal down window navigation" }
maps.t["<C-k>"] = { "<Cmd>wincmd k<cr>", desc = "Terminal up window navigation" }
maps.t["<C-l>"] = { "<Cmd>wincmd l<cr>", desc = "Terminal right window navigation" }
-- Plugin Manager --
maps.n["<Leader>p"] = M.sections.p
maps.n["<Leader>ph"] = {
function()
require("lazy").home()
end,
desc = "Home",
}
maps.n["<Leader>pi"] = {
function()
require("lazy").install()
end,
desc = "Install",
}
maps.n["<Leader>pu"] = {
function()
require("lazy").update()
end,
desc = "Update",
}
maps.n["<Leader>ps"] = {
function()
require("lazy").sync()
end,
desc = "Sync",
}
maps.n["<Leader>px"] = {
function()
require("lazy").clean()
end,
desc = "Clean",
}
maps.n["<Leader>pc"] = {
function()
require("lazy").check()
end,
desc = "Check",
}
maps.n["<Leader>pl"] = {
function()
require("lazy").log()
end,
desc = "Log",
}
maps.n["<Leader>pr"] = {
function()
require("lazy").restore()
end,
desc = "Restore",
}
maps.n["<Leader>pp"] = {
function()
require("lazy").profile()
end,
desc = "Profile",
}
maps.n["<Leader>pd"] = {
function()
require("lazy").debug()
end,
desc = "Debug",
}
maps.n["<Leader>p?"] = {
function()
require("lazy").help()
end,
desc = "Help",
}
if f.is_available("bufferline.nvim") then
maps.n["<S-l>"] = {
function()
require("bufferline").cycle(1)
end,
desc = "Switch to next buffer",
}
maps.n["<S-h>"] = {
function()
require("bufferline").cycle(-1)
end,
desc = "Switch to previous buffer",
}
maps.n["<A-l>"] = {
function()
require("bufferline").move(1)
end,
desc = "Move buffer to next",
}
maps.n["<A-h>"] = {
function()
require("bufferline").move(-1)
end,
desc = "Move buffer to previous",
}
maps.n["<Leader>b"] = M.sections.b
maps.n["<Leader>bc"] = {
function()
require("bufferline").close_others()
end,
desc = "Close other buffers",
}
maps.n["<Leader>bl"] = {
function()
require("bufferline").close_in_direction("left")
end,
desc = "Close lefthand buffers",
}
maps.n["<Leader>br"] = {
function()
require("bufferline").close_in_direction("right")
end,
desc = "Close righthand buffers",
}
maps.n["<Leader>bs"] = M.sections.bs
maps.n["<Leader>bse"] = {
function()
require("bufferline").sort_by("extension")
end,
desc = "By extension",
}
maps.n["<Leader>bsd"] = {
function()
require("bufferline").sort_by("directory")
end,
desc = "By directory",
}
maps.n["<Leader>bsr"] = {
function()
require("bufferline").sort_by("relative_directory")
end,
desc = "By relative directory",
}
maps.n["<Leader>bst"] = {
function()
require("bufferline").sort_by("tabs")
end,
desc = "By tabs",
}
end
if f.is_available("Comment.nvim") then
maps.n["<Leader>/"] = {
function()
require("Comment.api").toggle.linewise.count(vim.v.count > 0 and vim.v.count or 1)
end,
desc = "Toggle comment line",
}
maps.v["<Leader>/"] = {
"<esc><Cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>",
desc = "Toggle comment for selection",
}
end
if f.is_available("gitsigns.nvim") then
maps.n["<Leader>g"] = M.sections.g
maps.n["]g"] = {
function()
require("gitsigns").next_hunk()
end,
desc = "Next Git hunk",
}
maps.n["[g"] = {
function()
require("gitsigns").prev_hunk()
end,
desc = "Previous Git hunk",
}
maps.n["<Leader>gl"] = {
function()
require("gitsigns").blame_line()
end,
desc = "View Git blame",
}
maps.n["<Leader>gL"] = {
function()
require("gitsigns").blame_line({ full = true })
end,
desc = "View full Git blame",
}
maps.n["<Leader>gp"] = {
function()
require("gitsigns").preview_hunk()
end,
desc = "Preview Git hunk",
}
maps.n["<Leader>gh"] = {
function()
require("gitsigns").reset_hunk()
end,
desc = "Reset Git hunk",
}
maps.n["<Leader>gr"] = {
function()
require("gitsigns").reset_buffer()
end,
desc = "Reset Git buffer",
}
maps.n["<Leader>gs"] = {
function()
require("gitsigns").stage_hunk()
end,
desc = "Stage Git hunk",
}
maps.n["<Leader>gS"] = {
function()
require("gitsigns").stage_buffer()
end,
desc = "Stage Git buffer",
}
maps.n["<Leader>gu"] = {
function()
require("gitsigns").undo_stage_hunk()
end,
desc = "Unstage Git hunk",
}
maps.n["<Leader>gd"] = {
function()
require("gitsigns").diffthis()
end,
desc = "View Git diff",
}
end
if f.is_available("taolf") then
maps.n["<Leader>e"] = M.sections.e
maps.n["E"] = {
function()
require("taolf").start({ dir = "fd" })
end,
desc = "File manager",
}
maps.n["gE"] = { "<Noop>" }
maps.n["<Leader>ee"] = {
function()
require("taolf").start()
end,
desc = "File manager",
}
maps.n["<Leader>eg"] = {
function()
require("taolf").start({ dir = "gwd" })
end,
desc = "File manager in git working directory",
}
maps.n["<Leader>ef"] = {
function()
require("taolf").start({ dir = "fd" })
end,
desc = "File manager in open file's working directory",
}
end
if f.is_available("mason.nvim") then
maps.n["<Leader>pm"] = { "<Cmd>Mason<cr>", desc = "Mason" }
end
if f.is_available("aerial.nvim") then
maps.n["<leader>l"] = M.sections.l
maps.n["<leader>lS"] = {
function()
require("aerial").toggle()
end,
desc = "Symbols outline",
}
end
if f.is_available("telescope.nvim") then
maps.n["<Leader>f"] = M.sections.f
maps.n["<Leader>g"] = M.sections.g
maps.n["<Leader>gb"] = {
function()
require("telescope.builtin").git_branches({ use_file_path = true })
end,
desc = "Git branches",
}
maps.n["<Leader>gc"] = {
function()
require("telescope.builtin").git_commits({ use_file_path = true })
end,
desc = "Git commits (repository)",
}
maps.n["<Leader>gC"] = {
function()
require("telescope.builtin").git_bcommits({ use_file_path = true })
end,
desc = "Git commits (current file)",
}
maps.n["<Leader>gt"] = {
function()
require("telescope.builtin").git_status({ use_file_path = true })
end,
desc = "Git status",
}
maps.n["<Leader>f<CR>"] = {
function()
require("telescope.builtin").resume()
end,
desc = "Resume previous search",
}
maps.n["<Leader>f'"] = {
function()
require("telescope.builtin").marks()
end,
desc = "Find marks",
}
maps.n["<Leader>f/"] = {
function()
require("telescope.builtin").current_buffer_fuzzy_find()
end,
desc = "Find words in current buffer",
}
maps.n["<Leader>fc"] = {
function()
require("telescope.builtin").grep_string()
end,
desc = "Find word under cursor",
}
maps.n["<Leader>fC"] = {
function()
require("telescope.builtin").commands()
end,
desc = "Find commands",
}
maps.n["<Leader>ff"] = {
function()
require("telescope.builtin").find_files()
end,
desc = "Find files",
}
maps.n["<Leader>fF"] = {
function()
require("telescope.builtin").find_files({ hidden = true, no_ignore = true })
end,
desc = "Find all files",
}
maps.n["<Leader>fh"] = {
function()
require("telescope.builtin").help_tags()
end,
desc = "Find help",
}
maps.n["<Leader>fk"] = {
function()
require("telescope.builtin").keymaps()
end,
desc = "Find keymaps",
}
maps.n["<Leader>fm"] = {
function()
require("telescope.builtin").man_pages()
end,
desc = "Find man",
}
maps.n["<Leader>fo"] = {
function()
require("telescope.builtin").oldfiles()
end,
desc = "Find history",
}
maps.n["<Leader>fr"] = {
function()
require("telescope.builtin").registers()
end,
desc = "Find registers",
}
maps.n["<Leader>fw"] = {
function()
require("telescope.builtin").live_grep()
end,
desc = "Find words",
}
-- maps.n["<Leader>fb"] = { function() require("telescope.builtin").buffers() end, desc = "Find buffers" }
maps.n["<Leader>ft"] = {
function()
require("telescope").extensions["todo-comments"].todo()
end,
desc = "Find buffers",
}
maps.n["<Leader>fW"] = {
function()
require("telescope.builtin").live_grep({
additional_args = function(args)
return vim.list_extend(args, { "--hidden", "--no-ignore" })
end,
})
end,
desc = "Find words in all files",
}
maps.n["<Leader>l"] = M.sections.l
maps.n["<Leader>ls"] = {
function()
local aerial_avail, _ = pcall(require, "aerial")
if aerial_avail then
require("telescope").extensions.aerial.aerial()
else
require("telescope.builtin").lsp_document_symbols()
end
end,
desc = "Search symbols",
}
end
if f.is_available("toggleterm.nvim") then
maps.n["<leader>t"] = M.sections.t
if vim.fn.executable("lazygit") == 1 then
maps.n["<leader>g"] = M.sections.g
maps.n["<leader>gg"] = {
function()
local worktree = f.file_worktree()
local flags = worktree and (" --work-tree=%s --git-dir=%s"):format(worktree.toplevel, worktree.gitdir)
or ""
f.toggle_term_cmd("lazygit " .. flags)
end,
desc = "ToggleTerm lazygit",
}
maps.n["<leader>tl"] = maps.n["<leader>gg"]
end
if vim.fn.executable("node") == 1 then
maps.n["<leader>tn"] = {
function()
f.toggle_term_cmd("node")
end,
desc = "ToggleTerm node",
}
end
if vim.fn.executable("gdu") == 1 then
maps.n["<leader>tu"] = {
function()
f.toggle_term_cmd("gdu")
end,
desc = "ToggleTerm gdu",
}
end
if vim.fn.executable("btm") == 1 then
maps.n["<leader>tt"] = {
function()
f.toggle_term_cmd("btm")
end,
desc = "ToggleTerm btm",
}
end
local python = vim.fn.executable("python") == 1 and "python" or vim.fn.executable("python3") == 1 and "python3"
if python then
maps.n["<leader>tp"] = {
function()
f.toggle_term_cmd(python)
end,
desc = "ToggleTerm python",
}
end
maps.n["<leader>tf"] = { "<Cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" }
maps.n["<leader>th"] = { "<Cmd>ToggleTerm direction=horizontal<cr>", desc = "ToggleTerm horizontal split" }
maps.n["<C-z>"] = { "<Cmd>ToggleTerm<cr>", desc = "Toggle terminal" }
maps.t["<C-z>"] = maps.n["<F7>"]
end
if f.is_available("nvim-dap") then
local conditional_breakpoint = function()
vim.ui.input({ prompt = "Condition: " }, function(condition)
if condition then
require("dap").set_breakpoint(condition)
end
end)
end
maps.n["<leader>d"] = M.sections.d
maps.v["<leader>d"] = M.sections.d
maps.n["<F5>"] = {
function()
require("dap").continue()
end,
desc = "Debugger: Start",
}
maps.n["<S-F5>"] = {
function()
require("dap").terminate()
end,
desc = "Debugger: Stop",
}
maps.n["<S-F9>"] = { conditional_breakpoint, desc = "Debugger: Conditional Breakpoint" }
maps.n["<C-F5>"] = {
function()
require("dap").restart_frame()
end,
desc = "Debugger: Restart",
}
maps.n["<F6>"] = {
function()
require("dap").pause()
end,
desc = "Debugger: Pause",
}
maps.n["<F9>"] = {
function()
require("dap").toggle_breakpoint()
end,
desc = "Debugger: Toggle Breakpoint",
}
maps.n["<F10>"] = {
function()
require("dap").step_over()
end,
desc = "Debugger: Step Over",
}
maps.n["<F11>"] = {
function()
require("dap").step_into()
end,
desc = "Debugger: Step Into",
}
maps.n["<S-F11>"] = {
function()
require("dap").step_out()
end,
desc = "Debugger: Step Out",
}
maps.n["<leader>db"] = {
function()
require("dap").toggle_breakpoint()
end,
desc = "Toggle Breakpoint (F9)",
}
maps.n["<leader>dB"] = {
function()
require("dap").clear_breakpoints()
end,
desc = "Clear Breakpoints",
}
maps.n["<leader>dc"] = {
function()
require("dap").continue()
end,
desc = "Start/Continue (F5)",
}
maps.n["<leader>dC"] = { conditional_breakpoint, desc = "Conditional Breakpoint (S-F9)" }
maps.n["<leader>di"] = {
function()
require("dap").step_into()
end,
desc = "Step Into (F11)",
}
maps.n["<leader>do"] = {
function()
require("dap").step_over()
end,
desc = "Step Over (F10)",
}
maps.n["<leader>dO"] = {
function()
require("dap").step_out()
end,
desc = "Step Out (S-F11)",
}
maps.n["<leader>dq"] = {
function()
require("dap").close()
end,
desc = "Close Session",
}
maps.n["<leader>dQ"] = {
function()
require("dap").terminate()
end,
desc = "Terminate Session (S-F5)",
}
maps.n["<leader>dp"] = {
function()
require("dap").pause()
end,
desc = "Pause (F6)",
}
maps.n["<leader>dr"] = {
function()
require("dap").restart_frame()
end,
desc = "Restart (C-F5)",
}
maps.n["<leader>dR"] = {
function()
require("dap").repl.toggle()
end,
desc = "Toggle REPL",
}
maps.n["<leader>ds"] = {
function()
require("dap").run_to_cursor()
end,
desc = "Run To Cursor",
}
if f.is_available("nvim-dap-ui") then
maps.n["<leader>dE"] = {
function()
vim.ui.input({ prompt = "Expression: " }, function(expr)
if expr then
require("dapui").eval(expr, { enter = true })
end
end)
end,
desc = "Evaluate Input",
}
maps.v["<leader>dE"] = {
function()
require("dapui").eval()
end,
desc = "Evaluate Input",
}
maps.n["<leader>du"] = {
function()
require("dapui").toggle()
end,
desc = "Toggle Debugger UI",
}
maps.n["<leader>dh"] = {
function()
require("dap.ui.widgets").hover()
end,
desc = "Debugger Hover",
}
end
end
if f.is_available("nvim-ufo") then
maps.n["zR"] = {
function()
require("ufo").openAllFolds()
end,
desc = "Open all folds",
}
maps.n["zM"] = {
function()
require("ufo").closeAllFolds()
end,
desc = "Close all folds",
}
maps.n["zr"] = {
function()
require("ufo").openFoldsExceptKinds()
end,
desc = "Fold less",
}
maps.n["zm"] = {
function()
require("ufo").closeFoldsWith()
end,
desc = "Fold more",
}
maps.n["zp"] = {
function()
require("ufo").peekFoldedLinesUnderCursor()
end,
desc = "Peek fold",
}
end
M.maps = maps
return M