remap.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. nmap("<Space>", "")
  2. vim.g.mapleader = " "
  3. vim.g.maplocalleader = " "
  4. nmap("Y", "yy")
  5. nmap("<leader><leader>", "<c-^>", { desc = "Switch to last buffer" })
  6. nmap("<M-h>", ":vertical resize +3<CR>", { desc = "Resize window" })
  7. nmap("<M-l>", ":vertical resize -3<CR>", { desc = "Resize window" })
  8. nmap("<M-k>", ":resize +3<CR>", { desc = "Resize window" })
  9. nmap("<M-j>", ":resize -3<CR>", { desc = "Resize window" })
  10. vim.cmd([[
  11. nnoremap <silent> <C-j> <C-d>
  12. nnoremap <silent> <C-k> <C-u>
  13. ]])
  14. nmap("n", "nzz", { desc = "Move to next search match" })
  15. nmap("N", "Nzz", { desc = "Move to previous search match" })
  16. nmap("*", "*zz", { desc = "Move to next search match" })
  17. nmap("#", "#zz", { desc = "Move to previous search match" })
  18. nmap("g*", "g*zz", { desc = "Move to next search match" })
  19. nmap("g#", "g#zz", { desc = "Move to previous search match" })
  20. -- stay in indent mode
  21. vmap("<", "<gv", { desc = "Indent left" })
  22. vmap(">", ">gv", { desc = "Indent right" })
  23. -- keep register after paste
  24. map("x", "p", [["_dP]])
  25. map({ "n", "o", "x" }, "<s-h>", "^", { desc = "Move to first non-blank character" })
  26. map({ "n", "o", "x" }, "<s-l>", "g_", { desc = "Move to last non-blank character" })
  27. nmap("<leader>q", ":q<CR>", { desc = "Quit" })
  28. nmap("<leader>Q", function()
  29. vim.api.nvim_command("bd!|qall!")
  30. end, { desc = "Quit all" })
  31. -- create a user command to save without formatting :noa w
  32. vim.api.nvim_create_user_command("W", function()
  33. if vim.fn.empty(vim.fn.expand("%:t")) == 1 then
  34. Snacks.notifier.notify("Buffer is empty, not saving", vim.log.levels.ERROR)
  35. return
  36. end
  37. vim.api.nvim_command("noa w")
  38. end, { nargs = 0, desc = "Save without formatting" })
  39. -- move lines
  40. vmap("J", ":m '>+1<CR>gv=gv", { desc = "Move lines down" })
  41. vmap("K", ":m '<-2<CR>gv=gv", { desc = "Move lines up" })
  42. -- undo tree
  43. nmap("<leader>u", vim.cmd.UndotreeToggle)
  44. -- nnoremap yl :let @" = expand("%:p")<cr>
  45. nmap("yl", function()
  46. local file = vim.fn.expand("%:p")
  47. print("Copied path to clipboard: " .. file)
  48. -- copy to os clipboard
  49. vim.fn.setreg("+", file)
  50. end, { desc = "Copy file path to clipboard" })
  51. nmap("<Leader>x", "<cmd>!chmod +x %<cr>", { desc = "Make file executable" })
  52. vim.g.user_emmet_leader_key = ","
  53. nmap("<leader>gp", "<CMD>Git push<CR>", { desc = "Git push" })
  54. -- reset cmdheight
  55. nmap("<leader>ch", function()
  56. vim.o.cmdheight = 1
  57. end, { desc = "Reset cmdheight" })
  58. nmap("<leader>w", function()
  59. vim.api.nvim_command("w")
  60. end, { desc = "Save" })
  61. nmap("<leader>W", function()
  62. vim.api.nvim_command("wa")
  63. end, { desc = "Save all" })
  64. -- format json using jq
  65. nmap("<leader>jq", ":%!jq '.'<CR>", { desc = "Format json using jq" })
  66. vmap("<leader>jq", ":!jq '.'<CR>", { desc = "Format json using jq" })
  67. -- Navigate quickfix list
  68. nmap("qj", "<cmd>cnext<cr>", { desc = "Next quickfix item" })
  69. nmap("qk", "<cmd>cprev<cr>", { desc = "Previous quickfix item" })
  70. nmap("<Esc>", "<cmd>nohlsearch<CR>", { desc = "Clear search highlights" })
  71. -- Launch lazygit in a new tmux pane, exits when done
  72. nmap("<leader>lg", "<cmd>!tmux new-window -c " .. vim.fn.getcwd() .. " -- lazygit <CR><CR>", { desc = "LazyGit" })