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

Loading directory of files, into a single file, in VIM

Expand Messages
  • Russell Urquhart
    Hi, While still pretty new to Vim, i wanted to ask if this is possible. I have a directory of html files, (that are actually xml files, misnamed extension
    Message 1 of 7 , Feb 16, 2013
    • 0 Attachment
      Hi,

      While still pretty new to Vim, i wanted to ask if this is possible.

      I have a directory of html files, (that are actually xml files, misnamed extension wise.) I would like to have all those files loaded, one after another into a single file, is that possible in Vim?

      Thanks for any help,


      Russ

      --
      --
      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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Dave R
      Hi Russ, Try looking up help on the read Vim command. I think... Go to bottom of current file, do :r YourNextFilename and it reads it into your current
      Message 2 of 7 , Feb 16, 2013
      • 0 Attachment

        Hi Russ,
        Try looking up help on the 'read' Vim command.  I think... Go to bottom of current file, do ":r YourNextFilename" and it reads it into your current file at your text cursor. There may be a more automatic technique as well that the group could suggest. You might also want to consider a command line utility, like for Windows/dos, "cat YourFilename >> CombinedFilename". I think the single '>' overwrites target, but double appends.
        And then, I'm sure there are Unix command line utilities that are ported to Windows that are perfect for this kind of thing but that's a matter of downloading and learning how-to.

        On Feb 16, 2013 2:02 PM, "Russell Urquhart" <russurquhart1@...> wrote:


        Hi,

        While still pretty new to Vim, i wanted to ask if this is possible.

        I have  a directory of html files, (that are actually xml files, misnamed extension wise.) I would like to have all those files loaded, one after another into a single file, is that possible in Vim?

        Thanks for any help,


        Russ

        --
        --
        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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.


        --
        --
        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
         
        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
         
         
      • Tim Chase
        ... There are several ways to go about this. One can create the combined file on-disk with something like vim *.html ... which will load up each HTML file and
        Message 3 of 7 , Feb 16, 2013
        • 0 Attachment
          On 2013-02-16 13:02, Russell Urquhart wrote:
          > I have a directory of html files, (that are actually xml files,
          > misnamed extension wise.) I would like to have all those files
          > loaded, one after another into a single file, is that possible in
          > Vim?

          There are several ways to go about this. One can create the combined
          file on-disk with something like

          vim *.html
          :argdo w! >> combined.xml

          which will load up each HTML file and then iterate over them,
          appending them to a file on disk.

          Alternatively, you can accumulate them in a register, e.g. "z" with

          vim *.html
          :let @z='' | argdo %y Z
          :new
          "zpdd

          which will iterate over all your HTML files appending their contents
          to the "z" register (the uppercase version appends, as noted at
          ":help quotea"). It then creates a new buffer, pastes the contents
          of the "z" register, and deletes the blank line under which it was
          pasted.

          Note that in both case, you can modify the range to select a subset
          of the file, so if you just want to write the <body> content, you can
          do something like

          :argdo /<body/+1,/<\/body>/-1w! >> combined.xml

          Hope this gives you some options to work with.

          -tim




          --
          --
          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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • george gutman
          Jerry, Just got back to this issue... I actually had gotten this advice from Mr. Google, but it doesn t work for me, if I go into insert mode and type CTRL V,
          Message 4 of 7 , Mar 20 4:48 PM
          • 0 Attachment
            Jerry,

            Just got back to this issue...  I actually had gotten this advice from Mr. Google, but it doesn't work for me, if I go into insert mode and type CTRL V, all that happens is that the contents of the Windows scrap get pasted at the position of the cursor.  (I think I also replied on the group, but I'm not sure if it was successful...).

            Thanks,
             

            On Sat, Feb 16, 2013 at 4:20 AM, Jerry Rocteur <macosx@...> wrote:
            Hi George,

            On 16 Feb 2013, at 07:03, George Gutman wrote:

            > I'm using Vim under Windows (XP and 7).  I would like to universally
            > replace text which includes a CRLF with some other text.  In MSWord I can
            > represent CRLF as ^p, but MSWord unfortunately does not behave well with
            > the large files I'm working with.  So how can I do this in Vim?

            When you're in vi or vim, put yourself in insert mode and then type CTRL V

            Once you've typed CTRL V you can now type and control character, such as CTRL M or CTRL L

            CTRL M is carriage return
            CTRL L is line feed

            Having said that, a simple Google search would have given you the answers but also read these:

            http://dailyvim.blogspot.be/2009/10/ctrl-v-for-literal-characters.html
            http://www.bo.infn.it/alice/alice-doc/mll-doc/linux/vi-ex/node15.html
            http://vim.wikia.com/wiki/Entering_special_characters

            Jerry

            --
            --
            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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.



            --
            --
            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
             
            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
             
             
          • Gary Johnson
            ... To start with, Ctrl-V is the traditional character used to quote special characters such as control characters. Because Windows uses Ctrl-V for pasting,
            Message 5 of 7 , Mar 20 5:34 PM
            • 0 Attachment
              On 2013-03-20, george gutman wrote:
              > On Sat, Feb 16, 2013 at 4:20 AM, Jerry Rocteur wrote:
              >> Hi George,
              >>
              >> On 16 Feb 2013, at 07:03, George Gutman wrote:
              >>
              >>> I'm using Vim under Windows (XP and 7). I would like to universally
              >>> replace text which includes a CRLF with some other text. In MSWord I can
              >>> represent CRLF as ^p, but MSWord unfortunately does not behave well with
              >>> the large files I'm working with. So how can I do this in Vim?
              >>
              >> When you're in vi or vim, put yourself in insert mode and then type CTRL V
              >>
              >> Once you've typed CTRL V you can now type and control character, such as
              >> CTRL M or CTRL L
              >>
              >> CTRL M is carriage return
              >> CTRL L is line feed

              > Jerry,
              >
              > Just got back to this issue... I actually had gotten this advice from Mr.
              > Google, but it doesn't work for me, if I go into insert mode and type CTRL V,
              > all that happens is that the contents of the Windows scrap get pasted at the
              > position of the cursor. (I think I also replied on the group, but I'm not sure
              > if it was successful...).

              To start with, Ctrl-V is the traditional character used to quote
              special characters such as control characters. Because Windows uses
              Ctrl-V for pasting, Vim is often configured on Windows to use Ctrl-Q
              where it would normally use Ctrl-V. See

              :help CTRL-V-alternative
              :help i_CTRL-V

              That said, replacing CRLF is a whole other problem. CRLF is the
              DOS/Windows EOL sequence. Vim treats EOL sequences specially. They
              usually don't even appear in a buffer. How you treat them depends
              on what you want to do with them.

              If you have a file with only CRLF line endings and all you want to
              do is convert them to LF line endings, Vim can do that
              automatically. Vim will open that file as 'fileformat' "dos". You
              won't see any CRLFs in the buffer. Simply

              :set ff=unix
              :w

              and the file will be saved with LF (Unix) line endings.

              If you have a file that contains a mixture of CRLF and LF line
              endings, Vim will load that file as 'fileformat' "unix", hide all
              the LFs at the line endings, and show the CRs as ^M. You can delete
              all those ^Ms either by executing

              :%s/^Q^M//g

              where ^Q and ^M are Ctrl-Q and Ctrl-M, respectively, or by executing

              :%s/\r//g

              See

              :help /\r

              If none of that works for you, come back with a more specific
              explanation of what you are trying to do and we'll help you with the
              solution.

              HTH,
              Gary

              --
              --
              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

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            Your message has been successfully submitted and would be delivered to recipients shortly.