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.


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, '$')
  return l

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

Error management left as excercise to the reader.

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.