diff --git a/lua/basic.lua b/lua/basic.lua index f9eac8c..af4ed3d 100644 --- a/lua/basic.lua +++ b/lua/basic.lua @@ -59,6 +59,7 @@ M.load_default_options = function() loaded_netrwPlugin = 1, -- set leaderkey to space mapleader = " ", + maplocalleader = "\\", copilot_node_command = "~/.nodenv/versions/16.17.0/bin/node", } diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 7b1808f..cccec41 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -123,10 +123,17 @@ wk.register({ s = { ":Telescope current_buffer_fuzzy_find<CR>", "Searching in buffer" }, }, }) + +-- insert 模式下ctrl a e跳转开头结尾 +map("i", "<C-a>", "<C-o>I", opt) +map("i", "<C-e>", "<C-o>A", opt) + -- change left and right tab -- 左右Tab切换 map("n", "<C-h>", ":BufferLineCyclePrev<CR>", opt) map("n", "<C-l>", ":BufferLineCycleNext<CR>", opt) +map("i", "<C-h>", "<C-o>:BufferLineCyclePrev<CR>", opt) +map("i", "<C-l>", "<C-o>:BufferLineCycleNext<CR>", opt) -- Mason wk.register({ @@ -190,4 +197,23 @@ map("i", "<C-d>", ":lua require'dap'.continue()<CR>", opt) map("n", "<C-n>", ":lua require'dap'.step_into()<CR>", opt) map("n", "<C-o>", ":lua require'dap'.step_over()<CR>", opt) +-- set keymap based on file type +vim.cmd("autocmd FileType * lua SetKeybinds()") +function SetKeybinds() + local fileTy = vim.api.nvim_buf_get_option(0, "filetype") + local opts = { prefix = "<localleader>", buffer = 0 } + + if fileTy == "markdown" then + wk.register({ + ["t"] = { ":InsertNToc<CR>", "Insert table of content" }, + ["d"] = { ":HeaderDecrease<CR>", "All header decrease" }, + ["i"] = { ":HeaderIncrease<CR>", "All header increase" }, + }, opts) + -- elseif fileTy == "sh" then + -- wk.register({ + -- ["W"] = { ":w<CR>", "test write" }, + -- ["Q"] = { ":q<CR>", "test quit" }, + -- }, opts) + end +end return pluginKeys diff --git a/readme.md b/readme.md index 5b21026..a9bde2d 100644 --- a/readme.md +++ b/readme.md @@ -32,6 +32,7 @@ ## 快捷键 \<leader>键被配置为空格 + \<localleader>被配置为\\ ### 常用 | key | function | |----------------|-------------------------------------------| @@ -46,6 +47,12 @@ | , | 运行当前文件代码,需要自行配置各种语言 | | Ctrl-\\ | 打开终端 | +### Insert模式下特殊按键 +| key | function | +|--------|------------| +| Ctrl-a | 跳转到行首 | +| Ctrl-e | 跳转到行尾 | + ### Packer | key | function | |-------------|------------------------| @@ -60,6 +67,10 @@ | \<leader>lI | 打开Mason安装lsp dap 等任意服务 | | \<leader>ll | 打开Mason查看安装的服务 | | \<leader>lu | 卸载当前语言对应的lsp | +| \<leader>lr | 重启lsp | +| ]d | 跳转到函数定义 | +| ]i | 跳转到函数实现 | +| ]r | 跳转到函数引用 | ### git | key | function | @@ -83,6 +94,7 @@ | \<leader>bk | 关闭当前buffer | | \<leader>bc | 取消高亮(可用于搜索后取消高亮) | | \<leader>bo | 关闭其他buffer | +| \<leader>bs | 搜索当前buffer | ### window | key | function | @@ -100,6 +112,16 @@ | \<leader>fr | 最近打开的文件 | | \<leader>fs | 在项目文件中搜索字符串 | | \<leader>fp | 打开项目 | +| \<leader>fn | 新建文件 | + +### markdown +| key | function | +|-----------------|--------------------| +| \<leader>m | 预览markdown | +| \<localleader>t | 在当前位置插入目录 | +| \<localleader>d | 降低所有目录等级 | +| \<localleader>i | 升高所有目录等级 | + ## 问题 ### 根据文件类型启动某些功能