1

How can I send all writable buffers to an external command? For example,

:wa ! wc -l

does not work (gives trailing characters error). (Also, wa will not work anyway because it does not write unchanged buffers).

It needs to be writable buffers because I may have buffers like help open that are not writable that I do not want to include.

BTW, bufdo does not work, both because it includes read only buffers and because it executes the commands separately and therefore hangs the interface.

2

This is not easily doable. You need to script a little bit. Something like this should do it:

func! CollectContent()
  let l=[]
  for i in range(1,bufnr('$'))
    if bufexists(i) && getbufvar(i, '&modifiable')
        let l += getbufline(i, 1, '$')
    endif
  endfor
  return l
endfu

func! GetOutput()
  let cnt=CollectContent()
  let cmd='wc -l'
  let out=system(cmd, join(cnt, "\n")."\n")
  echo out
endfu

Error management left as excercise to the reader.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.