keybindings.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. -- Mode
  2. -- normal_mode = "n",
  3. -- insert_mode = "i",
  4. -- visual_mode = "v",
  5. -- visual_block_mode = "x",
  6. -- term_mode = "t",
  7. -- command_mode = "c",
  8. -- leader key 为空
  9. vim.g.mapleader = " "
  10. vim.g.maplocalleader = " "
  11. -- MAC 设置alt 键
  12. alt_send_esc = true
  13. local opt = {
  14. noremap = true,
  15. silent = true
  16. }
  17. -- 本地变量
  18. local map = vim.api.nvim_set_keymap
  19. -- 取消 s 默认功能
  20. map("n", "s", "", opt)
  21. map("n", "sv", ":vsp<CR>", opt)
  22. map("n", "sh", ":sp<CR>", opt)
  23. map("n", "sc", "<C-w>c", opt)
  24. map("n", "so", "<C-w>o", opt)
  25. -- 切换窗口
  26. map("n", "<A-Right>", "<C-w>l", opt)
  27. map("n", "<A-Down>", "<C-w>j", opt)
  28. map("n", "<A-Up>", "<C-w>k", opt)
  29. map("n", "<A-Left>", "<C-w>h", opt)
  30. -- 返回dashboard 主页
  31. map("n", "<leader>h", ":Dashboard<CR>", opt)
  32. -- gitsigns
  33. map("n", "git", ":Gitsigns toggle_current_line_blame<CR>", opt)
  34. -- lazygit
  35. map("n", "<leader>lg", ":LazyGit<CR>", opt)
  36. -- terminal 相关
  37. map("n", "<leader>t", ":FloatermToggle<CR>", opt)
  38. -- 高亮 intent
  39. map("n", "<leader>i", ":IndentGuidesToggle<CR>", opt)
  40. -- 代码缩进
  41. map("v", "<", "<gv", opt)
  42. map("v", ">", ">gv", opt)
  43. map("v", "J", ":move '>+1<CR>gv-gv>'", opt)
  44. map("v", "K", ":move '<-2<CR>gv-gv>'", opt)
  45. -- 保存配置
  46. map("n", "<leader>w", ":w<CR>", opt)
  47. map("n", "<leader>wq", ":wqa!<CR>", opt)
  48. -- 退出
  49. map("n", "qq", ":q!<CR>", opt)
  50. map("n", "<leader>q", ":qa!<CR>", opt)
  51. -- 上下滚动浏览
  52. map("n", "<A-j>", "5j", opt)
  53. map("n", "<A-k>", "5k", opt)
  54. map("v", "<A-j>", "5j", opt)
  55. map("v", "<A-k>", "5k", opt)
  56. -- Telescope 查找文件
  57. -- 文件名查找
  58. map("n", "<leader>f", ":Telescope find_files<CR>", opt)
  59. -- 全局搜索 关键词key 查找
  60. map("n", "<leader>k", ":Telescope live_grep<CR>", opt)
  61. -- git 文件
  62. map("n", "<leader>g", ":Telescope git_files<CR>", opt)
  63. -- project
  64. map("n", "<leader>p", ":Telescope projects<CR>", opt)
  65. -- packer update
  66. map("n", "<leader>u", ":PackerUpdate<CR>", opt)
  67. -- prettier
  68. map("n", "<leader>cf", ":Prettier<CR>", opt)
  69. -- 插件快捷键
  70. local pluginKeys = {}
  71. -- nvim-tree
  72. map("n", "<leader>e", ":NvimTreeToggle<CR>", opt)
  73. -- 列表快捷键
  74. pluginKeys.nvimTreeList = { -- 打开文件或文件夹
  75. {
  76. key = { "o", "<2-LeftMouse>" },
  77. action = "edit"
  78. }, {
  79. key = "<CR>",
  80. action = "system_open"
  81. }, -- v分屏打开文件
  82. {
  83. key = "v",
  84. action = "vsplit"
  85. }, -- h分屏打开文件
  86. {
  87. key = "h",
  88. action = "split"
  89. }, -- Ignore (node_modules)
  90. {
  91. key = "i",
  92. action = "toggle_ignored"
  93. }, -- Hide (dotfiles)
  94. {
  95. key = ".",
  96. action = "toggle_dotfiles"
  97. }, {
  98. key = "R",
  99. action = "refresh"
  100. }, -- 文件操作
  101. {
  102. key = "a",
  103. action = "create"
  104. }, {
  105. key = "d",
  106. action = "remove"
  107. }, {
  108. key = "r",
  109. action = "rename"
  110. }, {
  111. key = "x",
  112. action = "cut"
  113. }, {
  114. key = "c",
  115. action = "copy"
  116. }, {
  117. key = "p",
  118. action = "paste"
  119. }, {
  120. key = "y",
  121. action = "copy_name"
  122. }, {
  123. key = "Y",
  124. action = "copy_path"
  125. }, {
  126. key = "gy",
  127. action = "copy_absolute_path"
  128. }, {
  129. key = "I",
  130. action = "toggle_file_info"
  131. }, {
  132. key = "n",
  133. action = "tabnew"
  134. }, -- 进入下一级
  135. {
  136. key = { "]" },
  137. action = "cd"
  138. }, -- 进入上一级
  139. {
  140. key = { "[" },
  141. action = "dir_up"
  142. } }
  143. -- lsp 快捷键
  144. pluginKeys.lspList = function(bufnr)
  145. -- bufmap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opt)
  146. bufmap(bufnr, "n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opt)
  147. -- bufmap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.cade_action()<CR>", opt)
  148. bufmap(bufnr, "n", "<leader>ca", "<cmd>Lspsaga cade_action<CR>", opt)
  149. -- go to
  150. -- bufmap(bufnr, "n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opt)
  151. bufmap(bufnr, "n", "gd", "<cmd>Lspsaga goto_definition<CR>", opt)
  152. -- bufmap(bufnr, "n", "gd", "<cmd>Lspsaga peek_definition<CR>", opt)
  153. bufmap(bufnr, "n", "gt", "<cmd>Lspsaga goto_type_definition<CR>", opt)
  154. bufmap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opt)
  155. -- bufmap(bufnr, "n", "gh", "<cmd>lua vim.lsp.buf.hover()<CR>", opt)
  156. bufmap(bufnr, "n", "gh", "<cmd>Lspsaga hover_doc<CR>", opt)
  157. bufmap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opt)
  158. -- bufmap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opt)
  159. bufmap(bufnr, "n", "gr", "<cmd>Lspsaga lsp_finder<CR>", opt)
  160. -- diagnostic
  161. -- bufmap(bufnr, "n", "go", "<cmd>lua vim.diagnostic.open_float()<CR>", opt)
  162. bufmap(bufnr, "n", "go", "<cmd>Lspsaga show_line_diagnostics<CR>", opt)
  163. -- bufmap(bufnr, "n", "gn", "<cmd>lua vim.diagnostic.goto_next()<CR>", opt)
  164. bufmap(bufnr, "n", "gn", "<cmd>Lspsaga diagnostic_jump_next<CR>", opt)
  165. -- bufmap(bufnr, "n", "gp", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opt)
  166. bufmap(bufnr, "n", "gp", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opt)
  167. bufmap(bufnr, "n", "<leader>f", "<cmd>lua vim.lsp.buf.format({ async = true })<CR>", opt)
  168. bufmap(bufnr, "n", [[<M-\>]], "<cmd>Lspsaga term_toggle<CR>", opt)
  169. bufmap(bufnr, "t", [[<M-\>]], "<cmd>Lspsaga term_toggle<CR>", opt)
  170. end
  171. -- nvim-cmp 自动补全
  172. pluginKeys.cmp = function(cmp)
  173. return {
  174. -- 出现补全
  175. ["<A-.>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
  176. -- 取消
  177. ["<A-,>"] = cmp.mapping({
  178. i = cmp.mapping.abort(),
  179. c = cmp.mapping.close()
  180. }),
  181. -- 上一个
  182. ["<C-k>"] = cmp.mapping.select_prev_item(),
  183. -- 下一个
  184. ["<C-j>"] = cmp.mapping.select_next_item(),
  185. -- 确认
  186. ["<CR>"] = cmp.mapping.confirm({
  187. select = true,
  188. behavior = cmp.ConfirmBehavior.Replace
  189. }),
  190. -- 如果窗口内容太多,可以滚动
  191. ["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
  192. ["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
  193. }
  194. end
  195. return pluginKeys