mappings.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. local opts = { silent = true }
  2. -- ; as :
  3. vim.keymap.set({'n', 'v'}, ';', ':')
  4. -- leave insert mode via jj
  5. vim.keymap.set('i', 'jj', '<ESC>', opts)
  6. -- j/k with wraps
  7. vim.keymap.set({'n', 'v'}, 'j', 'gj', opts)
  8. vim.keymap.set({'n', 'v'}, 'k', 'gk', opts)
  9. -- leave insert mode with <ESC><ESC>
  10. vim.keymap.set('t', '<ESC><ESC>', '<C-\\><C-N>', opts)
  11. -- select pasted text
  12. vim.keymap.set('n', 'gp', '`[v`]', opts)
  13. -- pickers
  14. vim.keymap.set('n', '<C-P>', '<cmd>lua project_files()<CR>', opts)
  15. vim.keymap.set('n', '<C-O>', '<cmd>Telescope buffers<CR>', opts)
  16. vim.keymap.set('n', '<Leader>fg', '<cmd>lua commit_files()<CR>', opts)
  17. vim.keymap.set('n', '<Leader>ff', '<cmd>Telescope live_grep<CR>', opts)
  18. -- jumplist navigation
  19. vim.keymap.set('n', '[f', '<C-O>', opts)
  20. vim.keymap.set('n', ']f', '<C-I>', opts)
  21. -- quickfix navigation
  22. vim.keymap.set('n', '[q', '<cmd>cprevious<CR>', opts)
  23. vim.keymap.set('n', ']q', '<cmd>cnext<CR>', opts)
  24. -- conflicts navigation
  25. vim.keymap.set('n', '[x', '?^[<lt>=>]\\{7}<CR>', opts)
  26. vim.keymap.set('n', ']x', '/^[<lt>=>]\\{7}<CR>', opts)
  27. -- hunk navigation
  28. vim.keymap.set('n', '[c', '<cmd>Gitsigns prev_hunk<CR>', opts)
  29. vim.keymap.set('n', ']c', '<cmd>Gitsigns next_hunk<CR>', opts)
  30. -- window navigation
  31. vim.keymap.set('n', '[w', '<C-w>W', opts)
  32. vim.keymap.set('n', ']w', '<C-w>w', opts)
  33. -- cursor display
  34. vim.keymap.set('n', '<Leader>c', '<cmd>set cursorline! cursorcolumn!<CR>', opts)
  35. -- git
  36. -- open status in current split without special flag (so navigating away closes it)
  37. -- https://github.com/tpope/vim-fugitive/issues/1296
  38. vim.keymap.set('n', '<Leader>gs', '<cmd>Gedit :<CR>', opts)
  39. -- open in reverse to match order when rebasing
  40. vim.keymap.set('n', '<Leader>gll', '<cmd>Git log --reverse --oneline origin/HEAD..HEAD<CR>', opts)
  41. vim.keymap.set('n', '<Leader>gb', '<cmd>Telescope git_branches<CR>', opts)
  42. -- undotree
  43. vim.keymap.set('n', '<Leader>ut', '<cmd>UndotreeToggle<CR>', opts)
  44. -- opening terminals
  45. vim.keymap.set('n', '<Leader>tv', '<cmd>vsp term://$SHELL<CR>', opts)
  46. vim.keymap.set('n', '<Leader>to', '<cmd>term<CR>', opts)
  47. -- delete buffer
  48. vim.keymap.set('n', '<Leader>q', '<cmd>lua MiniBufremove.delete()<CR>', opts)
  49. vim.keymap.set('n', '<Leader>Q', '<cmd>lua MiniBufremove.delete(0, true)<CR>', opts)
  50. -- split/join
  51. vim.keymap.set('n', '<Leader>s', '<cmd>TSJSplit<CR>', opts)
  52. vim.keymap.set('n', '<Leader>j', '<cmd>TSJJoin<CR>', opts)
  53. -- diagnostics
  54. vim.keymap.set('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
  55. vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
  56. vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
  57. vim.keymap.set('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } })<CR>', opts)
  58. function on_attach(client, bufnr)
  59. local opts = { silent = true, buffer = bufnr }
  60. -- LSP-specific mappings
  61. vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  62. vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  63. vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  64. vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  65. vim.keymap.set({'n', 'i'}, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  66. vim.keymap.set('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  67. vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  68. vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  69. vim.keymap.set('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR><ESC>', opts)
  70. vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
  71. vim.keymap.set('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
  72. vim.keymap.set('n', '<Leader>fr', '<cmd>Telescope resume<CR>', opts)
  73. end