mirror of
https://github.com/cap153/nvim.git
synced 2026-07-16 22:16:54 +08:00
改用neovim内置的注释功能
This commit is contained in:
parent
63f1d16bc4
commit
a7c0a23077
6 changed files with 160 additions and 183 deletions
|
|
@ -2,8 +2,8 @@
|
||||||
-- === map function
|
-- === map function
|
||||||
-- ===
|
-- ===
|
||||||
|
|
||||||
local function mapkey(mode, lhs, rhs)
|
local function mapkey(mode, lhs, rhs, opts)
|
||||||
vim.keymap.set(mode, lhs, rhs, { silent = true, nowait = true })
|
vim.keymap.set(mode, lhs, rhs, vim.tbl_extend("force", { silent = true, nowait = true }, opts or {}))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function mapcmd(key, cmd)
|
local function mapcmd(key, cmd)
|
||||||
|
|
@ -90,6 +90,8 @@ maplua({ "x", "o", "n" }, "<CR>", smart_select("select_parent", 1), "扩大 Tree
|
||||||
-- 缩小范围 (退格键):不断向下寻找子节点
|
-- 缩小范围 (退格键):不断向下寻找子节点
|
||||||
maplua({ "x", "o" }, "<BS>", smart_select("select_child", -1), "缩小 Treesitter/LSP 范围")
|
maplua({ "x", "o" }, "<BS>", smart_select("select_child", -1), "缩小 Treesitter/LSP 范围")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- ===
|
-- ===
|
||||||
-- === Cursor Movement
|
-- === Cursor Movement
|
||||||
-- ===
|
-- ===
|
||||||
|
|
@ -181,13 +183,9 @@ mapkey("x", "<tab>", ">gv")
|
||||||
-- === 批量替换
|
-- === 批量替换
|
||||||
-- ===
|
-- ===
|
||||||
|
|
||||||
-- 设置快捷键,替换所有文件内容
|
|
||||||
mapcmd("<leader>sa", "lua search_and_replace()")
|
|
||||||
-- 设置快捷键,替换当前文件内容
|
|
||||||
mapcmd("<leader>sr", "lua search_and_replace_current_file()")
|
|
||||||
|
|
||||||
-- 替换当前目录及子目录下所有文件内容
|
-- 替换当前目录及子目录下所有文件内容
|
||||||
function search_and_replace()
|
local function search_and_replace()
|
||||||
|
return function ()
|
||||||
-- 获取用户输入的查找内容,使用 input() 函数动态输入替换内容
|
-- 获取用户输入的查找内容,使用 input() 函数动态输入替换内容
|
||||||
local search_text = vim.fn.input("Search for: ")
|
local search_text = vim.fn.input("Search for: ")
|
||||||
|
|
||||||
|
|
@ -209,9 +207,11 @@ function search_and_replace()
|
||||||
print("Search or replace text cannot be empty.")
|
print("Search or replace text cannot be empty.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- 替换当前文件内容
|
-- 替换当前文件内容
|
||||||
function search_and_replace_current_file()
|
local function search_and_replace_current_file()
|
||||||
|
return function()
|
||||||
-- 获取用户输入的查找内容
|
-- 获取用户输入的查找内容
|
||||||
local search_text = vim.fn.input("Search for in current file: ")
|
local search_text = vim.fn.input("Search for in current file: ")
|
||||||
|
|
||||||
|
|
@ -228,6 +228,10 @@ function search_and_replace_current_file()
|
||||||
print("Search or replace text cannot be empty.")
|
print("Search or replace text cannot be empty.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
maplua("n","<leader>sa",search_and_replace(), "替换当前目录及子目录下所有文件内容")
|
||||||
|
maplua("n","<leader>sr",search_and_replace_current_file(), "替换当前文件内容")
|
||||||
|
|
||||||
-- ===
|
-- ===
|
||||||
-- === 临时“存档”文件当前的版本,并与后续的修改进行 diff 对比
|
-- === 临时“存档”文件当前的版本,并与后续的修改进行 diff 对比
|
||||||
|
|
@ -264,6 +268,12 @@ mapkey({ "n", "x", "o" }, "<LEADER><LEADER>", "<Esc>/<++><CR>:nohlsearch<CR>c4l"
|
||||||
-- 拼写检查
|
-- 拼写检查
|
||||||
mapcmd("<LEADER>sc", "set spell!")
|
mapcmd("<LEADER>sc", "set spell!")
|
||||||
|
|
||||||
|
-- 注释快捷键
|
||||||
|
mapkey("n", "<leader>cn", "gcc", { remap = true })
|
||||||
|
mapkey("x", "<leader>cn", "gc", { remap = true })
|
||||||
|
mapkey("n", "<leader>cu", "gcc", { remap = true })
|
||||||
|
mapkey("x", "<leader>cu", "gc", { remap = true })
|
||||||
|
|
||||||
-- ===
|
-- ===
|
||||||
-- === 运行代码(该功能已经迁移到plugins/coderunner.lua)
|
-- === 运行代码(该功能已经迁移到plugins/coderunner.lua)
|
||||||
-- ===
|
-- ===
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,6 @@ map:cmd('tu', 'enew')
|
||||||
-- 关闭当前缓冲区,neovim自带的,完整命令bdelete
|
-- 关闭当前缓冲区,neovim自带的,完整命令bdelete
|
||||||
map:cmd('tq', 'bd')
|
map:cmd('tq', 'bd')
|
||||||
|
|
||||||
-- 在缓冲区之间移动
|
|
||||||
map:cmd('tn', 'BufferLineCyclePrev')
|
|
||||||
map:cmd('ti', 'BufferLineCycleNext')
|
|
||||||
|
|
||||||
-- 移动缓冲区的位置
|
|
||||||
map:cmd('tmn', 'BufferLineMovePrev')
|
|
||||||
map:cmd('tmi', 'BufferLineMoveNext')
|
|
||||||
|
|
||||||
-- 关闭缓冲区
|
|
||||||
map:cmd('tN', 'BufferLineCloseLeft')
|
|
||||||
map:cmd('tI', 'BufferLineCloseRight')
|
|
||||||
map:cmd('tQ', 'BufferLineCloseOthers')
|
|
||||||
|
|
||||||
-- === 顶部标签栏 (Bufferline) ===
|
-- === 顶部标签栏 (Bufferline) ===
|
||||||
if vim.g.vscode then return end
|
if vim.g.vscode then return end
|
||||||
|
|
||||||
|
|
@ -31,6 +18,18 @@ vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
|
||||||
once = true,
|
once = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
PackUtils.load(P, function(plugin)
|
PackUtils.load(P, function(plugin)
|
||||||
|
-- 在缓冲区之间移动
|
||||||
|
map:cmd('tn', 'BufferLineCyclePrev')
|
||||||
|
map:cmd('ti', 'BufferLineCycleNext')
|
||||||
|
|
||||||
|
-- 移动缓冲区的位置
|
||||||
|
map:cmd('tmn', 'BufferLineMovePrev')
|
||||||
|
map:cmd('tmi', 'BufferLineMoveNext')
|
||||||
|
|
||||||
|
-- 关闭缓冲区
|
||||||
|
map:cmd('tN', 'BufferLineCloseLeft')
|
||||||
|
map:cmd('tI', 'BufferLineCloseRight')
|
||||||
|
map:cmd('tQ', 'BufferLineCloseOthers')
|
||||||
plugin.setup({
|
plugin.setup({
|
||||||
options = {
|
options = {
|
||||||
modified_icon = "",
|
modified_icon = "",
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
-- 注释快捷键
|
|
||||||
local map = require("core.keymap")
|
|
||||||
map:key("n", "<space>cn", "<Plug>kommentary_line_increase")
|
|
||||||
map:key("x", "<space>cn", "<Plug>kommentary_visual_increase<esc>") -- 选择模式下注释/反注释后退出该模式
|
|
||||||
map:key("n", "<space>cu", "<Plug>kommentary_line_decrease")
|
|
||||||
map:key("x", "<space>cu", "<plug>kommentary_visual_decrease<esc>")
|
|
||||||
|
|
||||||
local P = {
|
|
||||||
name = "b3nj5m1n/kommentary", -- 仓库名
|
|
||||||
module = "kommentary.config", -- require模块名
|
|
||||||
}
|
|
||||||
|
|
||||||
-- 懒加载触发器
|
|
||||||
vim.api.nvim_create_autocmd({
|
|
||||||
"UIEnter",
|
|
||||||
}, {
|
|
||||||
callback = function()
|
|
||||||
vim.schedule(function()
|
|
||||||
PackUtils.load(P, function(plugin)
|
|
||||||
plugin.configure_language("default", {
|
|
||||||
prefer_single_line_comments = true,
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
@ -23,8 +23,6 @@ local specs = {
|
||||||
"https://github.com/kevinhwang91/promise-async",
|
"https://github.com/kevinhwang91/promise-async",
|
||||||
-- conform.lua 格式化工具formatter
|
-- conform.lua 格式化工具formatter
|
||||||
"https://github.com/stevearc/conform.nvim",
|
"https://github.com/stevearc/conform.nvim",
|
||||||
-- kommentary.lua 注释插件
|
|
||||||
"https://github.com/b3nj5m1n/kommentary",
|
|
||||||
-- noice.lua 取代消息、命令行和弹出菜单的 UI
|
-- noice.lua 取代消息、命令行和弹出菜单的 UI
|
||||||
"https://github.com/folke/noice.nvim",
|
"https://github.com/folke/noice.nvim",
|
||||||
"https://github.com/MunifTanjim/nui.nvim",
|
"https://github.com/MunifTanjim/nui.nvim",
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,6 @@
|
||||||
"rev": "11be32be3761c6263df2311afb6baa0de0863967",
|
"rev": "11be32be3761c6263df2311afb6baa0de0863967",
|
||||||
"src": "https://github.com/MysticalDevil/inlay-hints.nvim"
|
"src": "https://github.com/MysticalDevil/inlay-hints.nvim"
|
||||||
},
|
},
|
||||||
"kommentary": {
|
|
||||||
"rev": "d5a111a3bc4109a8f913a5863c9092b3b3801482",
|
|
||||||
"src": "https://github.com/b3nj5m1n/kommentary"
|
|
||||||
},
|
|
||||||
"mason-lspconfig.nvim": {
|
"mason-lspconfig.nvim": {
|
||||||
"rev": "25f609e7fca78af7cede4f9fa3af8a94b1c4950b",
|
"rev": "25f609e7fca78af7cede4f9fa3af8a94b1c4950b",
|
||||||
"src": "https://github.com/williamboman/mason-lspconfig.nvim"
|
"src": "https://github.com/williamboman/mason-lspconfig.nvim"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue