vim-sandwich
vim-sandwich copied to clipboard
Throw a error after remove empty line.
I had this config:
\ {
\ 'buns': ["[", "]"],
\ 'input': ['z'],
\ 'kind': ['add'],
\ 'linewise': 1,
\ 'command': ["'[+1,']-1g/^\\s*$/d", "'[+1,']-1s/\\(.\\+\\)/\"\\1\",/g", "'[,']normal! =="]
\ },
\ ]

It seems that the following replacement error is caused by the deletion of a line
Sorry for my late response, and it seems a little difficult situation. Actually, the three commands would not succeed even if executed manually because each command changes the marks '[, '].
A possible workaround is to make a function.
let g:sandwich#recipes += [
\ {
\ 'buns': ['[', ']'],
\ 'nesting': 1,
\ 'input': ['z'],
\ 'command': ['call SandwichQuoteInside()'],
\ },
\ ]
function! SandwichQuoteInside() abort
let l:start = line("'[") + 1
let l:end = line("']") - 1
execute printf('%d,%ds/\(.\+\)/"\1",/g', l:start, l:end)
execute printf('%d,%dnormal! ==', l:start, l:end)
execute printf('%d,%dg/^"\s*"$/d', l:start, l:end)
endfunction