123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- -- Mode
- -- normal_mode = "n",
- -- insert_mode = "i",
- -- visual_mode = "v",
- -- visual_block_mode = "x",
- -- term_mode = "t",
- -- command_mode = "c",
- -- leader key 为空
- vim.g.mapleader = " "
- vim.g.maplocalleader = " "
- -- MAC 设置alt 键
- alt_send_esc = true
- local opt = {
- noremap = true,
- silent = true
- }
- -- 本地变量
- local map = vim.api.nvim_set_keymap
- -- 取消 s 默认功能
- map("n", "s", "", opt)
- map("n", "sv", ":vsp<CR>", opt)
- map("n", "sh", ":sp<CR>", opt)
- map("n", "sc", "<C-w>c", opt)
- map("n", "so", "<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>h", ":Dashboard<CR>", opt)
- -- gitsigns
- map("n", "git", ":Gitsigns toggle_current_line_blame<CR>", opt)
- -- lazygit
- map("n", "<leader>lg", ":LazyGit<CR>", opt)
- -- terminal 相关
- map("n", "<leader>t", ":FloatermToggle<CR>", opt)
- -- 高亮 intent
- map("n", "<leader>i", ":IndentGuidesToggle<CR>", 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>w", ":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)
- -- 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 = {}
- -- nvim-tree
- map("n", "<leader>e", ":NvimTreeToggle<CR>", opt)
- -- 列表快捷键
- pluginKeys.nvimTreeList = { -- 打开文件或文件夹
- {
- key = { "o", "<2-LeftMouse>" },
- action = "edit"
- }, {
- key = "<CR>",
- action = "system_open"
- }, -- v分屏打开文件
- {
- key = "v",
- action = "vsplit"
- }, -- h分屏打开文件
- {
- key = "h",
- action = "split"
- }, -- Ignore (node_modules)
- {
- key = "i",
- action = "toggle_ignored"
- }, -- Hide (dotfiles)
- {
- key = ".",
- action = "toggle_dotfiles"
- }, {
- key = "R",
- action = "refresh"
- }, -- 文件操作
- {
- key = "a",
- action = "create"
- }, {
- key = "d",
- action = "remove"
- }, {
- key = "r",
- action = "rename"
- }, {
- key = "x",
- action = "cut"
- }, {
- key = "c",
- action = "copy"
- }, {
- key = "p",
- action = "paste"
- }, {
- key = "y",
- action = "copy_name"
- }, {
- key = "Y",
- action = "copy_path"
- }, {
- key = "gy",
- action = "copy_absolute_path"
- }, {
- key = "I",
- action = "toggle_file_info"
- }, {
- key = "n",
- action = "tabnew"
- }, -- 进入下一级
- {
- key = { "]" },
- action = "cd"
- }, -- 进入上一级
- {
- key = { "[" },
- action = "dir_up"
- } }
- -- 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
|