debian-dots

dotfiles (does the obvious)
git clone [email protected]:dracuxan/debian-dots.git
Log | Files | Refs | README | LICENSE

keymaps.lua (2692B)


      1 local vim = vim
      2 local vk = vim.keymap.set
      3 
      4 -- Leader
      5 vim.g.mapleader = " "
      6 vim.g.maplocalleader = " "
      7 
      8 -- Defaults
      9 local opts = { noremap = true, silent = true }
     10 
     11 -- Insert
     12 vk("i", "jj", "<Esc>", opts)
     13 vk("i", "<C-b>", "<C-o>^", opts)
     14 vk("i", "<C-e>", "<C-o>$", opts)
     15 
     16 -- Normal/Visual
     17 vk({ "n", "v" }, "<Space>", "<Nop>", { silent = true })
     18 
     19 -- Save
     20 vk("n", "<C-s>", "<cmd> w <CR>", opts)
     21 vk("i", "<C-s>", "<Esc><cmd> w <CR>", opts)
     22 vk("n", "<leader>s", "<cmd> noautocmd w <CR>", opts)
     23 vk("n", "<leader>a", "<cmd> AutoSession search <CR>", opts)
     24 
     25 -- Edit
     26 vk("n", "x", '"_x', opts)
     27 
     28 -- Resize
     29 vk("n", "<Up>", ":resize -2<CR>", opts)
     30 vk("n", "<Down>", ":resize +2<CR>", opts)
     31 vk("n", "<Left>", ":vertical resize -2<CR>", opts)
     32 vk("n", "<Right>", ":vertical resize +2<CR>", opts)
     33 
     34 -- Buffers
     35 vk("n", "<Tab>", ":bnext<CR>", opts)
     36 vk("n", "<S-Tab>", ":bprevious<CR>", opts)
     37 vk("n", "<leader>x", ":bdelete!<CR>", opts)
     38 vk("n", "<leader>x", function()
     39 	local bufnr = vim.api.nvim_get_current_buf() -- Get the current buffer number
     40 	local buffers = vim.fn.getbufinfo({ buflisted = 1 }) -- Get list of open buffers
     41 
     42 	if #buffers > 1 then
     43 		vim.cmd("bnext") -- Switch to the next buffer
     44 	else
     45 		vim.cmd("enew") -- Open a new empty buffer if it's the last one
     46 	end
     47 
     48 	vim.cmd("bdelete! " .. bufnr) -- Delete the previous buffer
     49 end, opts)
     50 
     51 -- Windows
     52 vk("n", "<C-k>", ":wincmd k<CR>", opts)
     53 vk("n", "<C-j>", ":wincmd j<CR>", opts)
     54 vk("n", "<C-h>", ":wincmd h<CR>", opts)
     55 vk("n", "<C-l>", ":wincmd l<CR>", opts)
     56 
     57 -- Visual
     58 vk("v", "<", "<gv", opts)
     59 vk("v", ">", ">gv", opts)
     60 vk("v", "p", '"_dP', opts)
     61 
     62 -- Diagnostics
     63 vk("n", "<leader>d", vim.diagnostic.open_float, { desc = "Open floating diagnostic message" })
     64 vk("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostics list" })
     65 
     66 -- Reload
     67 local new_opts = { desc = "Reload current Lua file", noremap = true, silent = true }
     68 vk("n", "<leader>rr", ":luafile %<CR>", new_opts)
     69 
     70 -- Lazy
     71 vk("n", "<leader>l", "<cmd>Lazy<CR>", opts)
     72 
     73 -- Snacks
     74 vk("n", "<M-\\>", function()
     75 	Snacks.explorer()
     76 end, { desc = "Toggle Snacks Explorer" })
     77 
     78 -- Quit
     79 vk("n", "<C-q>", "<cmd> qa <CR>", opts)
     80 vk("i", "<C-q>", "<cmd> qa <CR>", opts)
     81 vk("n", "qq", "<cmd> q <CR>", opts)
     82 
     83 -- Telescope
     84 vk(
     85 	"n",
     86 	"<leader>ft",
     87 	"<cmd> TodoTelescope <CR>",
     88 	{ desc = "[F]ind [T]odos using telescope", noremap = true, silent = true }
     89 )
     90 
     91 -- File reload
     92 vk("n", "<leader>fr", ":checktime<CR>", { desc = "Check external file changes" })
     93 vk("n", "<leader>fr!", ":edit!<CR>", { desc = "Force reload file" })
     94 
     95 -- Terminal
     96 vk("t", "<C-h>", [[<C-\><C-N><C-w>h]])
     97 vk("t", "<C-j>", [[<C-\><C-N><C-w>j]])
     98 vk("t", "<C-k>", [[<C-\><C-N><C-w>k]])
     99 vk("t", "<C-l>", [[<C-\><C-N><C-w>l]])