mappings.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. vim.keymap.set('n', '<Leader>fr', '<cmd>Telescope resume<CR>', opts)
  19. vim.keymap.set('n', '<Leader>fp', '<cmd>Telescope pickers<CR>', opts)
  20. -- jumplist navigation
  21. vim.keymap.set('n', '[f', '<C-O>', opts)
  22. vim.keymap.set('n', ']f', '<C-I>', opts)
  23. -- quickfix navigation
  24. vim.keymap.set('n', '[q', '<cmd>cprevious<CR>', opts)
  25. vim.keymap.set('n', ']q', '<cmd>cnext<CR>', opts)
  26. -- conflicts navigation
  27. vim.keymap.set('n', '[x', '?^[<lt>=>]\\{7}<CR>', opts)
  28. vim.keymap.set('n', ']x', '/^[<lt>=>]\\{7}<CR>', opts)
  29. -- hunk navigation
  30. vim.keymap.set('n', '[c', '<cmd>Gitsigns prev_hunk<CR>', opts)
  31. vim.keymap.set('n', ']c', '<cmd>Gitsigns next_hunk<CR>', opts)
  32. -- window navigation
  33. vim.keymap.set('n', '[w', '<C-w>W', opts)
  34. vim.keymap.set('n', ']w', '<C-w>w', opts)
  35. -- cursor display
  36. vim.keymap.set('n', '<Leader>c', '<cmd>set cursorline! cursorcolumn!<CR>', opts)
  37. -- notification history
  38. vim.keymap.set('n', '<Leader>n', require('mini.notify').show_history, opts)
  39. -- git
  40. -- open status in current split without special flag (so navigating away closes it)
  41. -- https://github.com/tpope/vim-fugitive/issues/1296
  42. vim.keymap.set('n', '<Leader>gs', '<cmd>Gedit :<CR>', opts)
  43. -- open in reverse to match order when rebasing
  44. vim.keymap.set('n', '<Leader>gll', '<cmd>Git log --reverse --oneline origin/HEAD..HEAD<CR>', opts)
  45. vim.keymap.set('n', '<Leader>gb', '<cmd>Telescope git_branches<CR>', opts)
  46. -- undotree
  47. vim.keymap.set('n', '<Leader>ut', '<cmd>UndotreeToggle<CR>', opts)
  48. -- opening terminals
  49. vim.keymap.set('n', '<Leader>tv', '<cmd>vsp term://$SHELL<CR>', opts)
  50. vim.keymap.set('n', '<Leader>to', '<cmd>term $SHELL<CR>', opts)
  51. -- delete buffer
  52. vim.keymap.set('n', '<Leader>q', '<cmd>lua MiniBufremove.delete()<CR>', opts)
  53. vim.keymap.set('n', '<Leader>Q', '<cmd>lua MiniBufremove.delete(0, true)<CR>', opts)
  54. -- split/join
  55. vim.keymap.set('n', '<Leader>s', '<cmd>TSJSplit<CR>', opts)
  56. vim.keymap.set('n', '<Leader>j', '<cmd>TSJJoin<CR>', opts)
  57. -- diagnostics
  58. vim.keymap.set('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
  59. vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
  60. vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
  61. vim.keymap.set('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } })<CR>', opts)
  62. -- LSP-specific
  63. vim.api.nvim_create_autocmd('LspAttach', {
  64. callback = function(args)
  65. local client = vim.lsp.get_client_by_id(args.data.client_id)
  66. if client.name == 'dprint' or client.name == 'eslint' then
  67. -- mappings should have been attached by typescript and re-attaching can
  68. -- overwrite the typescript specific overrides
  69. end
  70. local opts = { silent = true, buffer = args.buf }
  71. vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  72. vim.keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
  73. vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  74. vim.keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<CR>', opts)
  75. vim.keymap.set({'n', 'i'}, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  76. vim.keymap.set('n', '<space>D', '<cmd>Telescope lsp_type_definitions<CR>', opts)
  77. vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  78. vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  79. vim.keymap.set('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
  80. vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
  81. vim.keymap.set('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
  82. if client.name == 'tsserver' then
  83. -- exclude import statements from reference search (may have false positives)
  84. vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
  85. vim.keymap.set('n', 'gD', '<cmd>Telescope lsp_definitions<CR>', opts)
  86. vim.keymap.set('n', 'gd', '<cmd>TypescriptGoToSourceDefinition<CR>', opts)
  87. end
  88. end,
  89. })