78 lines
4.1 KiB
Lua
78 lines
4.1 KiB
Lua
-- INFO: Maps leader to 'space'
|
|
vim.g.mapleader = " "
|
|
|
|
-- TIP: Unmap keymaps
|
|
-- ─< lua/keymaps.lua >─────────────────────────────────────────────────────────────────
|
|
local nomap = vim.keymap.set
|
|
nomap("i", "<C-k>", "")
|
|
nomap("n", "<C-k>", "")
|
|
nomap("n", "q", "")
|
|
nomap("v", "q", "")
|
|
nomap("v", "<leader>S", "")
|
|
|
|
-- INFO: vim.keymap.set with map()
|
|
local map = vim.keymap.set
|
|
|
|
map("n", "<Esc>", "<cmd>nohlsearch<CR>")
|
|
|
|
-- ─< Comment >─────────────────────────────────────────────────────────────────────────
|
|
-- INFO: makes instant comments, no plugin needet
|
|
map("n", "<S-c>", "gcc", { desc = "comment toggle", remap = true })
|
|
map("v", "<S-c>", "gc", { desc = "comment toggle", remap = true })
|
|
|
|
-- ─< Movement while in "insert"-mode >─────────────────────────────────────────────────
|
|
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" })
|
|
|
|
map("n", ";", ":", { desc = "CMD enter command mode" })
|
|
|
|
-- CTRL-C for escape
|
|
map({ "i", "n", "v" }, "<C-c>", "<ESC>")
|
|
|
|
map("n", "<leader>x", "<cmd>bd!<CR>")
|
|
|
|
-- ─< Disable arrow keys in normal mode >───────────────────────────────────────────────
|
|
map("n", "<left>", '<cmd>echo "Use h to move!!"<CR>')
|
|
map("n", "<right>", '<cmd>echo "Use l to move!!"<CR>')
|
|
map("n", "<up>", '<cmd>echo "Use k to move!!"<CR>')
|
|
map("n", "<down>", '<cmd>echo "Use j to move!!"<CR>')
|
|
|
|
map("n", "<leader>l", "<C-w><C-l>", { desc = "Move focus to the right window" })
|
|
map("n", "<leader>h", "<C-w><C-h>", { desc = "Move focus to the left window" })
|
|
map("n", "<leader>j", "<C-w><C-j>", { desc = "Move focus to the lower window" })
|
|
map("n", "<leader>k", "<C-w><C-k>", { desc = "Move focus to the upper window" })
|
|
|
|
-- map("n", "<leader>p", vim.cmd.Ex)
|
|
map("n", "<leader>q", vim.cmd.q)
|
|
map("n", "<leader>Q", "<cmd>q!<CR>")
|
|
map("n", "<leader>s", vim.cmd.w)
|
|
map("n", "<C-s>", vim.cmd.w)
|
|
|
|
-- Visual mode: Indent selected lines
|
|
-- INFO: got removed becouse of the mini-move plugin
|
|
-- map("v", "<Tab>", ">gv", { desc = "Indent and keep selection" })
|
|
-- map("v", "<S-Tab>", "<gv", { desc = "Unindent and keep selection" })
|
|
|
|
-- window management
|
|
map("n", "<leader>sv", "<C-w>v", { desc = "Split window vertically" }) -- split window vertically
|
|
map("n", "<leader>sh", "<C-w>s", { desc = "Split window horizontally" }) -- split window horizontally
|
|
|
|
-- ─< Terminal >────────────────────────────────────────────────────────────────────────
|
|
-- NOTE: This is only for terminal mode
|
|
map("t", "<C-x>", "<C-\\><C-N>", { desc = "terminal escape terminal mode" })
|
|
|
|
-- ──────────────────────────────< rename word under cursor >──────────────────────────────
|
|
-- map("n", "<leader>R", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
|
|
-- ───────────────< Enhanced word under cursor renaming in current buffer >────────────
|
|
map({ "n", "x" }, "<leader>R", function()
|
|
local text = vim.fn.mode() == "n" and vim.fn.expand("<cword>") or vim.fn.trim(vim.fn.getreg('"'))
|
|
vim.ui.input({ prompt = "Replace: ", default = text }, function(input)
|
|
if input and input ~= text then
|
|
vim.cmd(("keeppatterns %%s/%s/%s/g"):format(vim.pesc(text), vim.pesc(input)))
|
|
end
|
|
end)
|
|
end, { desc = "Rename in buffer" })
|