Wrap the visual selection in brackets and quotes
As usual using your plugin manager, e.g. lazy.nvim
local P = {
-- plugin spec
'doums/tenaille.nvim',
config = true,
}
local tenaille = require('tenaille')
-- Default config
tenaille.setup({
-- generate default mapping for each pair using
-- <leader>_open-character_
-- i.e.
-- <leader>" for double quotes ""
-- <leader>[ for brackets []
-- <leader>{ for curly braces {} and so on...
default_mapping = true,
-- supported brackets and quotes pairs
-- ⚠ only 2 character pairs are supported
pairs = {
{ '"', '"' },
{ "'", "'" },
{ '`', '`' },
{ '{', '}' },
{ '[', ']' },
{ '(', ')' },
{ '<', '>' },
},
})
Select the text you want to wrap then press the relevant key mapping
before | key | after |
---|---|---|
|text| |
<Leader>[ |
[|text|] |
|text| |
<Leader>" |
"|text|" |
|[text]| |
<Leader>( |
(|text|) |
|"text"| |
<Leader>' |
'|text|' |
|"text"| |
<Leader>" |
"|text|" |
|…|
selection
note: multiline selections are supported
tenaille.setup({
-- disable default key mapping
default_mapping = false,
)}
local wrap = require('tenaille').wrap
vim.keymap.set('v', '"', function() wrap({ '"', '"' }) end)
vim.keymap.set('v', "'", function() wrap({ "'", "'" }) end)
vim.keymap.set('v', '`', function() wrap({ '`', '`' }) end)
vim.keymap.set('v', '(', function() wrap({ '(', ')' }) end)
vim.keymap.set('v', '[', function() wrap({ '[', ']' }) end)
vim.keymap.set('v', '{', function() wrap({ '{', '}' }) end)
vim.keymap.set('v', '<', function() wrap({ '<', '>' }) end)
Mozilla Public License 2.0