Closed gaoqiangks closed 4 months ago
For me the highlight persists when I press S
; do you mind sending a set of screenshots to illustrate what happens with your setup?
For me the highlight persists when I press
S
; do you mind sending a set of screenshots to illustrate what happens with your setup?
https://github.com/kylechui/nvim-surround/assets/52161883/d6c06cbd-b34a-4644-8bd1-5390c40d5e19
Neovim version:
NVIM v0.10.0-dev Build type: RelWithDebInfo LuaJIT 2.1.1703358377 Run "nvim -V1 -v" for more info
OS version: (running on WSL2) Distributor ID: Ubuntu Description: Ubuntu Noble Numbat (development branch) Release: 24.04 Codename: noble
The following is my config. I delete all other settings, install only lazy.nvim and nvim-surround.
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup(
{
"kylechui/nvim-surround",
version = "*", -- Use for stability; omit to use `main` branch for the latest features
event = "VeryLazy",
config = function()
require("nvim-surround").setup({
move_cursor=false,
highlight={
duration=0,
},
--aliases=
--{
--["b"]="",
--},
--nvim-surround的操作是可重复的. 比如ysiw", 将一个单词用"引用后, 在下一个单词可以直接按.来重复
surrounds =
{
[")"] = {
add = function()
return { { "( " }, { " )" } }
end,
},
["("] = {
add = function()
return { { "(" }, { ")" } }
end,
},
["}"] = {
add = function()
return { { "{ " }, { " }" } }
end,
},
["{"] = {
add = function()
return { { "{" }, { "}" } }
end,
},
["["] = {
add = function()
return { { "[" }, { "]" } }
end,
},
["]"] = {
add = function()
return { { "[ " }, { " ]" } }
end,
},
["<"] = {
add = function()
return { { "<" }, { ">" } }
end,
},
[">"] = {
add = { "< " }, { " >" },
},
["E"] = {
add = function()
return {{ "\\begin{equation}" }, {"\\end{equation}"}}
end,
},
["T"] = {
add = function()
return {{ "\\begin{theorem}" }, {"\\end{theorem}"}}
end,
},
["e"] = {
add = function()
--ySSe 将当前行放在环境中. 比如*eq, 将会放在equation*环境中. eq会放在equation环境中.
local config = require("nvim-surround.config")
local env_input = config.get_input("surround输入环境名称:")
local env_map = {
["eq"]="equation",
["th"]="theorem",
["pr"]="proposition",
["le"]="lemma",
["re"]="remark",
["co"]="corollary",
["ex"]="exercise",
["em"]="example",
["de"]="definition",
["sp"]="split",
["qu"]="question",
}
local env = {
["equation"]=1,
["theorem"]=1,
["proposition"]=1,
["lemma"]=1,
["remark"]=1,
["corollary"]=1,
["exercise"]=1,
["example"]=1,
["definition"]=1,
["split"]=1,
["problem"]=1,
["question"]=1,
}
local final_env=nil
local no_n=0
if env_input==nil then
return
end
local first_letter=string.sub(env_input,1,1)
if first_letter=="*" then
no_n=1
env_input=string.sub(env_input,2,#env_input)
end
--local s=env[env_input]
--if s then
--final_env=env_input
--else
--local first_two_letters=string.sub(env_input,1,2)
--if first_two_letters then
--final_env=env_map[first_two_letters]
--else
for k, v in pairs(env) do
--string.find反回两个值, 第一个值是匹配开始的地方, 第二个值是匹配结束的地方
ibegin, iend=string.find(k, env_input)
if ibegin==1 then
final_env=k
break
end
end
--end
--end
if final_env then
if no_n==1 then
final_env=final_env.."*"
end
else
final_env=env_input
end
return { {"\\begin{"..final_env.."}"}, {"\\end{"..final_env.."}" }}
end,
},
--ysiwi 将当前单词放在textit环境中
["i"] = {
add = { "\\textit{", "}" },
find = "\\textit%b{}",
delete = "^(\\textit{)().-(})()$",
},
["1"] = {
add = { "\\textbf{", "}" },
find = "\\textbf%b{}",
delete = "^(\\textbf{)().-(})()$",
},
["b"] = {
add = { "\\mathbb{", "}" },
find = "\\mathbb%b{}",
delete = "^(\\mathbb{)().-(})()$",
},
--ysiwc 将当前单词放在命令中
--vimtex提供了dsc csc dic等删除, 修改命令等操作, 但是没有提供ys**
["c"] = {
add = function()
local config = require("nvim-surround.config")
local cmd_input = config.get_input("surround输入命令名称:")
if cmd_input==nil then
return
end
return {{"\\"..cmd_input.."{"}, {"}"}}
end,
find = "\\mathcal%b{}",
delete = "^(\\mathcal{)().-(})()$",
},
}
})
local keyset = vim.keymap.set
-- di" 删除引号之间的区域
-- da" 删除引号之间的区域,包含引号
-- ci" 修改引号之间的区域
-- ca" 修改引号之间的区域,包含引号
-- yi" yank引号之间的区域
-- ya" yank引号之间的区域,包含引号
-- ysl" 当前字符下加引号
-- ysaw" 当前单词下加引号
-- cs"' 双引号修改为单引号
--keyset("n", "[[", "ysl{ll", {silent=true})
--keyset("n", "]]", "ysl{ll", {silent=true})
--将当前行放置在latex环境中, 后面的动作是nvim-surround中定义的. cse,
--更改当前环境, 在vimtex中定义
keyset('n', '44', 'ysl$', {silent=true, remap=true})
keyset('n', 'ee', 'ySSe', {silent=true, remap=true})
keyset('n', 'EE', 'ySSE', {silent=true, remap=true})
end
}
)
Do you mind trying out the linked pull request? It seems to have fixed it on my machine.
Do you mind trying out the linked pull request? It seems to have fixed it on my machine.
Thank you. I think it works.
Checklist
:h nvim-surround
to see if there might be any relevant information there?Is your feature request related to a problem? Please describe. In visual mode, when
S
is pressed, highlight of selected text disappeared.Describe the solution you'd like
Is it possible to keep highlight when
S
is pressed?Additional context It's helpful if highlight is kept when
S
is pressed and it's much better if we can configure the highlight color of selected text whenS
is pressed.