keybindings.lua 6.2 KB

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