keybindings.lua 5.5 KB

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