2

To to find all modified files in Vim I type

:ls

This will give me a list like so

2  h   "index.html"                   line 98
3  h   "Category/Category.Bg_S.js"    line 1
4  h   "Category/Category.Box0_S.js"  line 1
5  +   "Category/Category.Box10_S.js" line 1
6      "Category/Category.Box11_S.js" line 1
7  +   "Category/Category.Box12_S.js" line 1

But if there are too many buffers this can be tedious. What I was thinking of doing would be something like:

:ls !grep +

to pipe the contents of vim's ls to shell's grep function. But it does not work. I therefore have 2 questions:

  1. How do I find out the list of all modified files?
  2. If there is an easier solution to 1), then how would I, for whatever reason, pass the output of a vim command to a shell command?
2
  • 1
    What do you want to do with those modified files? Commented Jan 14, 2012 at 22:23
  • @romainl I like to see what files are modified before exiting rather than blindly issuing :xa Commented Jan 15, 2012 at 23:10

1 Answer 1

2

The easiest way is probably to "redirect" the output to a vim variable, then filter it for modified buffers:

function! GetModifiedBuffers()
    redir => bufoutput
    buffers  " same as ls
    redir END
    return join(filter(split(bufoutput,'\n'),"v:val =~ '\\%8c+'"),'\n')
endfunction

Then do something like :echo GetModifiedBuffers() to show the list of modified buffers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.