mappings.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. -- allow pressing enter to autocomplete
  12. vim.keymap.set('i', '<CR>', 'pumvisible() ? "\\<C-y>" : "\\<CR>"', { expr = true })
  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>ff', '<cmd>Telescope live_grep<CR>', opts)
  17. -- cursor display
  18. vim.keymap.set('n', '<Leader>c', '<cmd>set cursorline! cursorcolumn!<CR>', opts)
  19. -- git
  20. vim.keymap.set('n', '<Leader>gs', '<cmd>Git<CR>', opts)
  21. vim.keymap.set('n', '<Leader>gll', '<cmd>Git log --oneline origin/HEAD..HEAD<CR>', opts)
  22. vim.keymap.set('n', '<Leader>gb', '<cmd>Telescope git_branches<CR>', opts)
  23. -- undotree
  24. vim.keymap.set('n', '<Leader>ut', '<cmd>UndotreeToggle<CR>', opts)
  25. -- opening terminals
  26. vim.keymap.set('n', '<Leader>tv', '<cmd>vsp term://$SHELL<CR>', opts)
  27. vim.keymap.set('n', '<Leader>to', '<cmd>term<CR>', opts)
  28. -- delete buffer
  29. vim.keymap.set('n', '<Leader>q', '<cmd>lua MiniBufremove.delete()<CR>', opts)
  30. -- diagnostics
  31. vim.keymap.set('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
  32. vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
  33. vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
  34. vim.keymap.set('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } })<CR>', opts)
  35. function on_attach(client, bufnr)
  36. local opts = { silent = true, buffer = bufnr }
  37. -- Enable completion triggered by <c-x><c-o>
  38. vim.bo.omnifunc = 'v:lua.MiniCompletion.completefunc_lsp'
  39. -- LSP-specific mappings
  40. vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  41. vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  42. vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  43. vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  44. vim.keymap.set('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  45. vim.keymap.set('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  46. vim.keymap.set('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  47. vim.keymap.set('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  48. vim.keymap.set('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  49. vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  50. vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  51. vim.keymap.set('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR><ESC>', opts)
  52. vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
  53. vim.keymap.set('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
  54. vim.keymap.set('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
  55. end