From 1291acb2500b5b1f12ba3db5e9c36f05d2c3c8c3 Mon Sep 17 00:00:00 2001 From: gameloader Date: Fri, 7 Oct 2022 13:00:21 +0800 Subject: [PATCH] add keybindings --- lua/keybindings.lua | 149 +++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 72 deletions(-) diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 0774c58..75b4f1d 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -3,34 +3,39 @@ local pluginKeys = {} -- 设定映射函数 -- set map function local map = vim.api.nvim_set_keymap -local opt = {noremap = true, silent = true } +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"}, + ["s"] = { ":w", "Save File" }, + ["q"] = { ":qa", "Quit All" }, + ["S"] = { ":wa", "Save All" }, }) -- code related -- 代码相关 map("n", ",", ":RunCode", opt) +-- git related +-- git 相关 +wk.register({ + ["g"] = { ":LazyGit", "Open lazygit" }, +}) -- file related -- 文件相关操作 wk.register({ - [""] = {"", "Last file"}, + [""] = { "", "Last file" }, }) wk.register({ - ["f"] = { - name = "+File", - p = {":Telescope projects", "Open project"}, - r = {":Telescope oldfiles", "Recent files"}, - n = {":enew", "New file"}, - }, + ["f"] = { + name = "+File", + p = { ":Telescope projects", "Open project" }, + r = { ":Telescope oldfiles", "Recent files" }, + n = { ":enew", "New file" }, + }, }) -- jk map to esc @@ -40,17 +45,17 @@ 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"}, - }, + ["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" }, + }, }) --一般映射方式 @@ -61,32 +66,32 @@ wk.register({ -- base operation for visual mode -- 可视模式下基本操作 -map('v', '<', '', '>gv', opt) +map("v", "<", "", ">gv", opt) --- nvimTree +-- nvimTree map("n", "n", ":NvimTreeToggle", opt) -- Packer wk.register({ - ["p"] = { - name = "+Packer", - i = {":PackerSync", "PackerSync"}, - s = {":PackerStatus", "PackerStatus"}, - c = {":PackerClean", "PackerClean"}, - }, + ["p"] = { + name = "+Packer", + i = { ":PackerSync", "PackerSync" }, + s = { ":PackerStatus", "PackerStatus" }, + c = { ":PackerClean", "PackerClean" }, + }, }) -- Bufferline and buffer related wk.register({ - ["b"] = { - name = "+Buffer", - k = {":bd!", "Kill buffer"}, - o = {":BufferLineCloseRight:BufferLineCloseLeft", "Close other buffer"}, - b = {":bp", "Last buffer"}, - n = {":ls", "Buffer numbers"}, - t = {":b ", "To buffer"}, - }, + ["b"] = { + name = "+Buffer", + k = { ":bd!", "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切换 @@ -95,55 +100,55 @@ 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"}, - } + ["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(), + return { + -- next option + -- 下一个 + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.confirm({ - select = true, - behavior = cmp.ConfirmBehavior.Replace - }) - } + [""] = 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"}, - } + ["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