123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- -- Mode
- -- normal_mode = "n",
- -- insert_mode = "i",
- -- visual_mode = "v",
- -- visual_block_mode = "x",
- -- term_mode = "t",
- -- command_mode = "c",
- -- leader key 为空
- local uConfig = require("uConfig")
- local keys = uConfig.keys
- vim.g.mapleader = " "
- vim.g.maplocalleader = " "
- -- MAC 设置alt 键
- alt_send_esc = true
- local opt = {
- noremap = true,
- silent = true,
- }
- local keymap = vim.keymap
- keymap.set("i", "jj", "<ESC>")
- -- 本地变量
- local map = vim.api.nvim_set_keymap
- -- 取消 s 默认功能
- map("n", "s", "", opt)
- map("n", "<leader>v", ":vsp<CR>", opt)
- map("n", "<leader>h", ":sp<CR>", opt)
- map("n", "<leader>c", "<C-w>c", opt)
- map("n", "<leader>o", "<C-w>o", opt)
- -- 切换窗口
- map("n", "<A-Right>", "<C-w>l", opt)
- map("n", "<A-Down>", "<C-w>j", opt)
- map("n", "<A-Up>", "<C-w>k", opt)
- map("n", "<A-Left>", "<C-w>h", opt)
- -- 返回dashboard 主页
- map("n", "<leader>hh", ":Dashboard<CR>", opt)
- -- gitsigns
- map("n", "git", ":Gitsigns toggle_current_line_blame<CR>", opt)
- -- lazygit
- map("n", "<leader>lg", ":LazyGit<CR>", opt)
- -- git diffview open
- map("n", "<leader>mg", ":DiffviewOpen<CR>", opt)
- -- terminal 相关
- map("n", "<leader>t", ":FloatermToggle<CR>", opt)
- -- 开启/关闭 全屏窗口
- map("n", "<leader>M", ":MaximizerToggle<CR>", opt)
- -- 开始错误列表
- map("n", "<leader>i", ":TroubleToggle<CR>", opt)
- -- rename 插件
- map("n", "<leader>rn", ":IncRename", opt)
- -- 代码缩进
- map("v", "<", "<gv", opt)
- map("v", ">", ">gv", opt)
- map("v", "J", ":move '>+1<CR>gv-gv>'", opt)
- map("v", "K", ":move '<-2<CR>gv-gv>'", opt)
- -- 保存配置
- map("n", "<leader>s", ":w<CR>", opt)
- map("n", "<leader>wq", ":wqa!<CR>", opt)
- -- 退出
- map("n", "qq", ":q!<CR>", opt)
- map("n", "<leader>q", ":qa!<CR>", opt)
- -- 上下滚动浏览
- map("n", "<A-j>", "5j", opt)
- -- map("n", "<A-k>", "5k", opt)
- map("v", "<A-j>", "5j", opt)
- map("v", "<A-k>", "5k", opt)
- -- hop 相关
- map("n", "<leader>hw", ":HopWord<CR>", opt)
- map("n", "<leader>hww", ":HopWordMW<CR>", opt)
- -- Telescope 查找文件
- -- 文件名查找
- map("n", "<leader>f", ":Telescope find_files<CR>", opt)
- -- 全局搜索 关键词key 查找
- map("n", "<leader>k", ":Telescope live_grep<CR>", opt)
- -- git 文件
- map("n", "<leader>g", ":Telescope git_files<CR>", opt)
- -- project
- map("n", "<leader>p", ":Telescope projects<CR>", opt)
- -- packer update
- map("n", "<leader>u", ":PackerUpdate<CR>", opt)
- -- prettier
- map("n", "<leader>cf", ":Prettier<CR>", opt)
- -- 插件快捷键
- local pluginKeys = {}
- local lsp = uConfig.lsp
- pluginKeys.mapLSP = function(mapbuf)
- -- rename
- --[[
- Lspsaga 替换 rn
- mapbuf("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opt)
- --]]
- mapbuf("n", lsp.rename, "<cmd>lua vim.lsp.buf.rename()<CR>")
- -- code action
- --[[
- Lspsaga 替换 ca
- mapbuf("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opt)
- --]]
- mapbuf("n", lsp.code_action, "<cmd>lua vim.lsp.buf.code_action()<CR>")
- -- go xx
- --[[
- mapbuf('n', 'gd', '<cmd>Lspsaga preview_definition<CR>', opt)
- mapbuf("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opt)
- --]]
- mapbuf("n", lsp.definition, function()
- require("telescope.builtin").lsp_definitions({
- initial_mode = "normal",
- -- ignore_filename = false,
- })
- end)
- --[[
- mapbuf("n", "gh", "<cmd>Lspsaga hover_doc<cr>", opt)
- Lspsaga 替换 gh
- --]]
- mapbuf("n", lsp.hover, "<cmd>lua vim.lsp.buf.hover()<CR>")
- --[[
- Lspsaga 替换 gr
- mapbuf("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opt)
- mapbuf("n", "gr", "<cmd>Lspsaga lsp_finder<CR>", opt)
- --]]
- mapbuf(
- "n",
- lsp.references,
- "<cmd>lua require'telescope.builtin'.lsp_references(require('telescope.themes').get_ivy())<CR>"
- )
- if vim.fn.has("nvim-0.8") == 1 then
- mapbuf("n", lsp.format, "<cmd>lua vim.lsp.buf.format({ async = true })<CR>")
- else
- mapbuf("n", lsp.format, "<cmd>lua vim.lsp.buf.formatting()<CR>")
- end
- --[[
- Lspsaga 替换 gp, gj, gk
- mapbuf("n", "gp", "<cmd>lua vim.diagnostic.open_float()<CR>", opt)
- mapbuf("n", "gj", "<cmd>lua vim.diagnostic.goto_next()<CR>", opt)
- mapbuf("n", "gk", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opt)
- --]]
- -- diagnostic
- -- mapbuf("n", "gp", "<cmd>Lspsaga show_line_diagnostics<CR>", opt)
- -- mapbuf("n", "gj", "<cmd>Lspsaga diagnostic_jump_next<cr>", opt)
- -- mapbuf("n", "gk", "<cmd>Lspsaga diagnostic_jump_prev<cr>", opt)
- mapbuf("n", lsp.open_flow, "<cmd>lua vim.diagnostic.open_float()<CR>")
- mapbuf("n", lsp.goto_next, "<cmd>lua vim.diagnostic.goto_next()<CR>")
- mapbuf("n", lsp.goto_prev, "<cmd>lua vim.diagnostic.goto_prev()<CR>")
- -- 未用
- -- mapbuf("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opt)
- -- mapbuf("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opt)
- -- mapbuf('n', '<leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
- -- mapbuf("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opt)
- -- mapbuf('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opt)
- -- mapbuf('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opt)
- -- mapbuf('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opt)
- -- mapbuf('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opt)
- end
- -- nvim-tree
- map("n", "<leader>e", ":NvimTreeToggle<CR>", opt)
- -- 列表快捷键
- -- lsp 快捷键
- pluginKeys.lspList = function(bufnr)
- -- bufmap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opt)
- bufmap(bufnr, "n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opt)
- -- bufmap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.cade_action()<CR>", opt)
- bufmap(bufnr, "n", "<leader>ca", "<cmd>Lspsaga cade_action<CR>", opt)
- -- go to
- -- bufmap(bufnr, "n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opt)
- bufmap(bufnr, "n", "gd", "<cmd>Lspsaga goto_definition<CR>", opt)
- -- bufmap(bufnr, "n", "gd", "<cmd>Lspsaga peek_definition<CR>", opt)
- bufmap(bufnr, "n", "gt", "<cmd>Lspsaga goto_type_definition<CR>", opt)
- bufmap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opt)
- -- bufmap(bufnr, "n", "gh", "<cmd>lua vim.lsp.buf.hover()<CR>", opt)
- bufmap(bufnr, "n", "gh", "<cmd>Lspsaga hover_doc<CR>", opt)
- bufmap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opt)
- -- bufmap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opt)
- bufmap(bufnr, "n", "gr", "<cmd>Lspsaga lsp_finder<CR>", opt)
- -- diagnostic
- -- bufmap(bufnr, "n", "go", "<cmd>lua vim.diagnostic.open_float()<CR>", opt)
- bufmap(bufnr, "n", "go", "<cmd>Lspsaga show_line_diagnostics<CR>", opt)
- -- bufmap(bufnr, "n", "gn", "<cmd>lua vim.diagnostic.goto_next()<CR>", opt)
- bufmap(bufnr, "n", "gn", "<cmd>Lspsaga diagnostic_jump_next<CR>", opt)
- -- bufmap(bufnr, "n", "gp", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opt)
- bufmap(bufnr, "n", "gp", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opt)
- bufmap(bufnr, "n", "<leader>f", "<cmd>lua vim.lsp.buf.format({ async = true })<CR>", opt)
- bufmap(bufnr, "n", [[<M-\>]], "<cmd>Lspsaga term_toggle<CR>", opt)
- bufmap(bufnr, "t", [[<M-\>]], "<cmd>Lspsaga term_toggle<CR>", opt)
- end
- -- nvim-cmp 自动补全
- pluginKeys.cmp = function(cmp)
- return {
- -- 出现补全
- ["<A-.>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
- -- 取消
- ["<A-,>"] = cmp.mapping({
- i = cmp.mapping.abort(),
- c = cmp.mapping.close(),
- }),
- -- 上一个
- ["<C-k>"] = cmp.mapping.select_prev_item(),
- -- 下一个
- ["<C-j>"] = cmp.mapping.select_next_item(),
- -- 确认
- ["<CR>"] = cmp.mapping.confirm({
- select = true,
- behavior = cmp.ConfirmBehavior.Replace,
- }),
- -- 如果窗口内容太多,可以滚动
- ["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
- ["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
- }
- end
- return pluginKeys
|