diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-09-01 19:21:35 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-09-01 19:22:22 +0200 |
commit | 9ee57db206f3d5ccf14784b9d7ecb2edf32850f1 (patch) | |
tree | 2eb958f7a1619a7680e9d683f5fa9c1a36b116ac /.config | |
parent | aee952bef2048a816f2759bee76a606fd2f55aa2 (diff) |
nvim: Add a surround for arrays/lists
Diffstat (limited to '.config')
-rw-r--r-- | .config/nvim/init.lua | 25 |
1 files changed, 25 insertions, 0 deletions
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, + }, + }, } } |