local pluginKeys = {} -- 设定映射函数 -- set map function local map = vim.api.nvim_set_keymap local opt = {noremap = true, silent = true } local wk = require("which-key") -- basic operation for write and quit -- 文件写入退出基本操作 wk.register({ ["s"] = {":w", "Save File"}, ["q"] = {":qa", "Quit All"}, ["S"] = {":wa", "Save All"}, }) -- code related -- 代码相关 map("n", ",", ":RunCode", opt) -- file related -- 文件相关操作 wk.register({ [""] = {"", "Last file"}, }) wk.register({ ["f"] = { name = "+File", p = {":Telescope projects", "Open project"}, r = {":Telescope oldfiles", "Recent files"}, n = {":enew", "New file"}, }, }) -- jk map to esc -- jk映射为esc键 map("i", "jk", "", opt) -- window operate by which-key -- 窗口操作(使用which-key快捷键设置) wk.register({ ["w"] = { name = "+Window", h = {"h", "To left"}, j = {"j", "To up"}, k = {"k", "To down"}, l = {"l", "To right"}, s = {":sp", "Split window"}, v = {":vsplit", "Vsplit window"}, d = {":close", "Close window"}, o = {":only", "Close others"}, }, }) --一般映射方式 --map("n", "wh", "h", opt) --map("n", "wj", "j", opt) --map("n", "wk", "k", opt) --map("n", "wl", "l", opt) -- base operation for visual mode -- 可视模式下基本操作 map('v', '<', '', '>gv', opt) -- nvimTree map("n", "n", ":NvimTreeToggle", opt) -- Packer wk.register({ ["p"] = { name = "+Packer", i = {":PackerSync", "PackerSync"}, s = {":PackerStatus", "PackerStatus"}, c = {":PackerClean", "PackerClean"}, }, }) -- Bufferline and buffer related wk.register({ ["b"] = { name = "+Buffer", k = {":Bdelete!", "Kill buffer"}, o = {":BufferLineCloseRight:BufferLineCloseLeft", "Close other buffer"}, b = {":bp", "Last buffer"}, n = {":ls", "Buffer numbers"}, t = {":b ", "To buffer"}, }, }) -- change left and right tab -- 左右Tab切换 map("n", "", ":BufferLineCyclePrev", opt) map("n", "", ":BufferLineCycleNext", opt) -- Mason wk.register({ ["l"] = { name = "+Lsp", i = {":LspInstall", "Install lsp"}, I = {":MasonInstall ", "Install any"}, l = {":Mason", "Mason info"}, u = {":MasonUninstall", "Uninstall lsp"}, U = {":MasonUninstallAll", "Unistall all"}, } }) -- Telescope map("n", "f", ":Telescope find_files", opt) -- cmpeletion keys -- 补全快捷键 pluginKeys.cmp = function(cmp) return { -- next option -- 下一个 [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace }) } end -- dap keymaps wk.register({ ["d"] = { name = "+Debug", r = {":lua require('dap').continue()", "Start debug"}, b = {":lua require('dap').toggle_breakpoint()", "Set breakpoint"}, c = {":lua require('dap').clear_breakpoints()", "Clear breakpoint"}, e = {":lua require'dap'.close()" .. ":lua require'dap'.terminate()" .. ":lua require'dap.repl'.close()" .. ":lua require'dapui'.close()" .. ":lua require('dap').clear_breakpoints()" .. "o", "Stop debug"}, } }) map("i", "", ":lua require'dap'.continue()", opt) map("n", "", ":lua require'dap'.step_into()", opt) map("n", "", ":lua require'dap'.step_over()", opt) return pluginKeys