machakann / vim-sandwich

Set of operators and textobjects to search/select/edit sandwiched texts.
1.44k stars 37 forks source link

Throw a error after remove empty line. #137

Open singlexyz opened 2 years ago

singlexyz commented 2 years ago

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

machakann commented 2 years ago

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