11

I want change fileformat of all the files.

So I open them use vim *.

Then I want to know if there is any simple way to do this, rather than typing :set fileformat=unix and :wfor each file one by one.

7
  • 1
    maybe you can use dos2unix for ALL your file in shell first
    – How Chen
    Commented Jan 6, 2013 at 3:37
  • @HowChen: thank you for providing this command. But I also want to do how to do same operation to all opened files in vim.
    – pktangyue
    Commented Jan 6, 2013 at 3:46
  • Why do you want to do it via vim? Why is that better than doing it in the shell with dos2unix? Commented Jan 6, 2013 at 4:06
  • @AndyLester: I have done that with dos2unix. And I think I may need to do same operation to many files in vim in other cases.
    – pktangyue
    Commented Jan 6, 2013 at 4:20
  • @pktangyue: You should not need to convert line endings in vim if you have already done it with dos2unix. Why do you think you need to do it in vim? Commented Jan 6, 2013 at 4:29

3 Answers 3

12

argdo is what you want, not bufdo, since you want to do it on every argument and you don't (necessarily) want to open every file first.

:argdo set ff=unix | update

should do the trick.

1
5

Maybe you need bufdo?

 :help bufdo
 bufdo[!] {cmd}     Execute {cmd} in each buffer in the buffer list.
 It works like doing this: 
                :bfirst
                :{cmd}
                :bnext
                :{cmd}
                etc.
3
  • Thank you. And I find other similar commands, like :windo :tabo :argdo.
    – pktangyue
    Commented Jan 6, 2013 at 7:32
  • An example would have been great
    – elysch
    Commented Mar 31, 2016 at 20:15
  • You can do it like this: :bufdo set ff=dos | w
    – elysch
    Commented Apr 12, 2016 at 18:07
4

Sure, you can do this using vim record and play feature. Follow these steps

1. Open all files using vim *
2. Press "qq" to start recording
3. :set ff=unix
4. :wn
5. Press again "q" to stop recording
6. Execute like "100@q"

Here 100 is the approximate number of files, but don't worry if you gave more number also. It'll stop when it finishes all buffer saying "E165: Cannot go beyond last file". You can get the number of file is by doing "ls | wc -l" before you open.

3
  • Or simply :bufdo set ff=dos | w
    – elysch
    Commented Apr 12, 2016 at 18:08
  • 1
    @sarath This is an old thread, but you let me know this method to apply something to all buffers, and this has saved me literally one (or may two) days in my precious life, and ensuring error free. The Good News should be spread for the whole human race. Commented Jan 2, 2017 at 18:35
  • Happy to hear that :)
    – sarath
    Commented Mar 18, 2017 at 11:21

Your Answer

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

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