vim-sandwich icon indicating copy to clipboard operation
vim-sandwich copied to clipboard

Throw a error after remove empty line.

Open fovj opened this issue 3 years ago • 1 comments

I had this config:

      \   {
      \     'buns':     ["[", "]"],
      \     'input':    ['z'],
      \     'kind':     ['add'],
      \     'linewise': 1,
      \     'command':  ["'[+1,']-1g/^\\s*$/d", "'[+1,']-1s/\\(.\\+\\)/\"\\1\",/g", "'[,']normal! =="]
      \   },
      \ ]

1111

It seems that the following replacement error is caused by the deletion of a line

fovj avatar Apr 24 '22 18:04 fovj

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

machakann avatar Apr 30 '22 13:04 machakann