用于自动补全成对括号、删除成对括号、跳出右括号、成对括号内回车缩进的 neovim 插件。
a simple autopairs plugin for neovim
|
表示光标
|
means cursor
-- before
if|
-- after input (
if()|
-- before
|
-- after input ([{'"
([{'"|"'}])
-- before
if(|)
-- after input <BS>(backspace)
if|
-- before
([{'"|"'}])
-- after input <BS> 6 times
|
-- before
if(|)
-- after input )
if()|
-- before
([{'"|"'}])
-- after input "'}])
([{'""'}])|
-- before
if(|)
-- after input <CR>(enter) which actually mapping to <CR><ESC>O
if(
|
)
-- before
|word
-- input "
"|"word"
-- input <C-E>
"word|"
-- input <C-Y>
"wor|"d
-- before
word
-- select string "word" and then input <Space>"
"word"
-- select string "word" or word, and then input <Space>" again
word
lazy.nvim :
{
"whitelies125/simple_pairs.nvim",
-- pairs config
opts = {
pairs_config = {
['{'] = '}',
['('] = ')',
['['] = ']',
['\''] = '\'',
['"'] = '"',
},
-- 用于 visual_model 下对选中字符串添加 pair 的 {lhs} 的前缀按键
-- 若不设置,或设为 nil,false 则表示不使用该功能
visual_model_trigger_key = "<Space>"
},
config = function(_, opts)
local sp = require("simple_pairs")
sp.setup(opts)
-- keymap
local keymap_opts = { noremap = true, silent = true }
local keymap_expr_opts = { noremap = true, silent = true, expr = true}
vim.keymap.set('i', '<CR>', function() return sp.when_input_enter() end, keymap_expr_opts)
vim.keymap.set('i', '<BS>', function() return sp.when_input_backspace() end, keymap_expr_opts)
vim.keymap.set('i', '<C-E>', sp.move_pair_right, keymap_opts)
vim.keymap.set('i', '<C-Y>', sp.move_pair_left, keymap_opts)
end,
}
https://github.com/m4xshen/autoclose.nvim, very tidy and helpful for me.