From 9ee57db206f3d5ccf14784b9d7ecb2edf32850f1 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 1 Sep 2024 19:21:35 +0200 Subject: nvim: Add a surround for arrays/lists --- .config/nvim/init.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 33cfe4d..0ae24da 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -346,6 +346,7 @@ require('nvim-treesitter.configs').setup { } -- nvim-surround +local surround_conf = require('nvim-surround.config') require('nvim-surround').setup { surrounds = { ['’'] = { @@ -371,6 +372,30 @@ require('nvim-surround').setup { find = '“[^“”]*”', delete = '^(“ *)().-( *”)()$', }, + + ['l'] = { + add = function() + local result = surround_conf.get_input('Array name: ') + if result then + return { { result .. '[' }, { ']' } } + end + end, + find = function() + return surround_conf.get_selection({ + pattern = '[^=%s%(%){}]+%b[]' + }) + end, + delete = '^(.-%[)().-(%])()$', + change = { + target = '^.-([%w_]+)()%[.-%]()()$', + replacement = function() + local result = surround_conf.get_input('Array name: ') + if result then + return { { result }, { '' } } + end + end, + }, + }, } } -- cgit v1.2.3