stitchy
2d5b5cb37d
Undotree did not have live updates like I wanted, so I have switched to the telescope one which does.
153 lines
6 KiB
Lua
153 lines
6 KiB
Lua
-- Keymap File
|
|
local map = vim.keymap.set
|
|
|
|
-- jk exit from insert mode
|
|
map("i", "jk", "<cmd>noh<cr><Esc>", { silent = true })
|
|
map({"n", "x"}, "<Esc>", "<cmd>noh<cr><Esc>", { silent = true })
|
|
|
|
----
|
|
-- Movements
|
|
----
|
|
|
|
-- More powerful J and K (use 6j/6k)
|
|
-- Via Pseudometa (https://nanotipsforvim.prose.sh/motion-setup--hjkl-as-amplified-hjkl)
|
|
map({ "n", "x" }, "<S-j>", "6j")
|
|
map({ "n", "x" }, "<S-k>", "6k")
|
|
|
|
-- And fix the keys to other ones
|
|
map({ "n", "x" }, "M", "J", { desc = "Merge" }) -- Replace the join command
|
|
map("n", "gh", vim.lsp.buf.hover, { desc = "Hover" }) -- Code action hover
|
|
|
|
|
|
-- Move to window using the <ctrl> hjkl keys
|
|
map("n", "<C-h>", "<C-w>h", { desc = "Go to left window", remap = true })
|
|
map("n", "<C-j>", "<C-w>j", { desc = "Go to lower window", remap = true })
|
|
map("n", "<C-k>", "<C-w>k", { desc = "Go to upper window", remap = true })
|
|
map("n", "<C-l>", "<C-w>l", { desc = "Go to right window", remap = true })
|
|
|
|
-- Move between buffers
|
|
map("n", "<S-h>", "<cmd>BufferLineCyclePrev<CR>", { desc = "Move buffer left", silent = true })
|
|
map("n", "<S-l>", "<cmd>BufferLineCycleNext<CR>", { desc = "Move buffer right", silent = true })
|
|
map("n", "<leader><", "<cmd>BufferLineMovePrev<CR>", { desc = "Move buffer left", silent = true })
|
|
map("n", "<leader>>", "<cmd>BufferLineMoveNext<CR>", { desc = "Move buffer right", silent = true })
|
|
|
|
-- ToggleTerm Bindings
|
|
map("n", "<leader>a", "<cmd>ToggleTerm name=main<CR>", { desc = "Floating Terminal", silent = true })
|
|
|
|
-- Undotree
|
|
map("n", "<leader>fu", "<cmd>Telescope undo<cr>")
|
|
----
|
|
-- Cool Macros
|
|
----
|
|
|
|
-- Quit All
|
|
map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit all" })
|
|
|
|
-- Copy and paste from system clipboard
|
|
map({ "n", "x" }, "<Leader>y", '"+y', { desc = "Yank to system clipboard", silent = true })
|
|
map({ "n", "x" }, "<Leader>p", '"+p', { desc = "Paste after from system clipboard", silent = true })
|
|
map({ "n", "x" }, "<Leader>P", '"+P', { desc = "Paste before from system clipboard", silent = true })
|
|
|
|
-- Neotree
|
|
map("n", "<leader>e", function()
|
|
require("neo-tree.command").execute({ action = "show", position = "right", toggle = true, dir = vim.loop.cwd() })
|
|
end, { desc = "Open Neotree", remap = true })
|
|
|
|
|
|
-- Conform Formatting
|
|
map({ "n", "v" }, "<leader>mp", function()
|
|
require("conform").format({
|
|
lsp_fallback = true,
|
|
async = false,
|
|
timeout_ms = 500,
|
|
})
|
|
end, { desc = "Format file or range (in visual mode)" })
|
|
|
|
-- diagnostic
|
|
---@param next "f"|"b"
|
|
---@param severity "ERROR"|"WARN"?
|
|
local diagnostic_goto = function(next, severity)
|
|
local go = (next == "f") and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
|
|
local severity_index = severity and vim.diagnostic.severity[severity] or nil
|
|
return function()
|
|
go({ severity = severity_index })
|
|
end
|
|
end
|
|
map("n", "<leader>cd", vim.diagnostic.open_float, { desc = "Line Diagnostics" })
|
|
map("n", "]d", diagnostic_goto("f"), { desc = "Next Diagnostic" })
|
|
map("n", "[d", diagnostic_goto("b"), { desc = "Prev Diagnostic" })
|
|
map("n", "]e", diagnostic_goto("f", "ERROR"), { desc = "Next Error" })
|
|
map("n", "[e", diagnostic_goto("b", "ERROR"), { desc = "Prev Error" })
|
|
map("n", "]w", diagnostic_goto("f", "WARN"), { desc = "Next Warning" })
|
|
map("n", "[w", diagnostic_goto("b", "WARN"), { desc = "Prev Warning" })
|
|
|
|
----
|
|
-- Plugins
|
|
----
|
|
|
|
-- Telescope (fuzzy finder)
|
|
local function telescope_git_fallback()
|
|
vim.fn.system("git rev-parse --is-inside-work-tree")
|
|
local is_git_repo = vim.v.shell_error == 0
|
|
|
|
if is_git_repo then
|
|
require("telescope.builtin").git_files()
|
|
else
|
|
require("telescope.builtin").find_files()
|
|
end
|
|
end
|
|
local function telescope_files()
|
|
require("telescope.builtin").find_files({ cwd = vim.uv.cwd() })
|
|
end
|
|
local function telescope_oldfiles()
|
|
require("telescope.builtin").oldfiles({ cwd = vim.uv.cwd() })
|
|
end
|
|
local function telescope_live_grep()
|
|
vim.fn.system("git rev-parse --is-inside-work-tree")
|
|
local is_git_repo = vim.v.shell_error == 0
|
|
local git_root = vim.fn.fnamemodify(vim.fn.finddir(".git", ".;"), ":h")
|
|
|
|
require("telescope.builtin").live_grep({
|
|
cwd = is_git_repo and git_root or vim.uv.cwd(),
|
|
})
|
|
end
|
|
map("n", "<leader><space>", telescope_git_fallback, { desc = "Find files (git/fallback, cwd)" })
|
|
map("n", "<leader>ff", telescope_files, { desc = "Find files (cwd)" })
|
|
map("n", "<leader>fo", telescope_oldfiles, { desc = "Find files (cwd)" })
|
|
map("n", "<leader>/", telescope_live_grep, { desc = "Live grep (cwd)" })
|
|
map("n", "<leader>,", require("telescope.builtin").buffers, { desc = "Find buffers" })
|
|
map("n", "<leader>\"", require("telescope.builtin").registers, { desc = "Find registers" })
|
|
|
|
|
|
----
|
|
-- Fixes
|
|
----
|
|
|
|
-- Proper Wrap Navigation
|
|
map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
|
map({ "n", "x" }, "<Down>", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
|
map({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
|
map({ "n", "x" }, "<Up>", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
|
|
|
-- Auto Re-highlight After Indent
|
|
map("v", "<", "<gv")
|
|
map("v", ">", ">gv")
|
|
|
|
-- Saner Movement of nN
|
|
map("n", "n", "'Nn'[v:searchforward].'zv'.'zz'", { expr = true, desc = "Next search result" })
|
|
map("x", "n", "'Nn'[v:searchforward].'zz'", { expr = true, desc = "Next search result" })
|
|
map("o", "n", "'Nn'[v:searchforward].'zz'", { expr = true, desc = "Next search result" })
|
|
map("n", "N", "'nN'[v:searchforward].'zv'.'zz'", { expr = true, desc = "Prev search result" })
|
|
map("x", "N", "'nN'[v:searchforward].'zz'", { expr = true, desc = "Prev search result" })
|
|
map("o", "N", "'nN'[v:searchforward].'zz'", { expr = true, desc = "Prev search result" })
|
|
|
|
-- Terminal Mappings
|
|
map("t", "<esc><esc>", "<c-\\><c-n>", { desc = "Enter Normal Mode" })
|
|
map("t", "<C-h>", "<cmd>wincmd h<cr>", { desc = "Go to left window" })
|
|
map("t", "<C-j>", "<cmd>wincmd j<cr>", { desc = "Go to lower window" })
|
|
map("t", "<C-k>", "<cmd>wincmd k<cr>", { desc = "Go to upper window" })
|
|
map("t", "<C-l>", "<cmd>wincmd l<cr>", { desc = "Go to right window" })
|
|
map("t", "<C-/>", "<cmd>close<cr>", { desc = "Hide Terminal" })
|
|
map("t", "<c-_>", "<cmd>close<cr>", { desc = "which_key_ignore" })
|
|
|
|
|