Loading ...
Sorry, an error occurred while loading the content.

134628Re: is there an easy way to merge many files into one with label?

Expand Messages
  • ping
    Nov 20, 2012
    • 0 Attachment
      On 11/17/2012 01:50 PM, Tim Chase wrote:
      > On 11/16/12 18:36, Ant wrote:
      >> this one is something I need help in. Say I have thousands of
      >> files and I wanted to concatenate them all into one. THis is easy
      >> to do, I can just do it outside Vim using bash script "cat * >
      >> allfiles.txt" or something.
      >> But how would you concatenate heaps of files together, separating
      >> them by its filename or some unique thing
      > You allude to how you get the source of your filenames ("*" = all
      > files in the current directory), so to do similarly in Vim, I might
      > do something like
      > :enew
      > :r! /bin/ls " on *nix
      > :r! dir /b " on Win32
      > :%sort " optionally sort, as dir/ls may not return sorted
      > " though you could pass switches to ls/dir to sort
      > :1d " delete the first blank line
      > :g/^/-put=repeat('=',50)|+|exec 'read '.getline('.')
      > " insert a divider of 50 "=" characters,
      > " move back to the line with the filename,
      > " read the file named on the given line
      > This also has the advantage that, if you have the filenames in a
      > file already, you can just use that, instead of reading the
      > filenames into the file contents. In theory, the above should also
      > work with subdirectories too if you need.
      > -tim

      :g/^/-put=repeat('=',50)|+|exec 'read '.getline('.')

      this is really nice to learn.

      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Show all 7 messages in this topic