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

Re: vim command to include a file into current file

Expand Messages
  • Javier Mediavilla Vegas
    ... I read more carefully tim response, because I didn t get the first time. Folds could be a point buy I prefer that the action to be managed by vim so I
    Message 1 of 9 , Aug 17, 2013
    • 0 Attachment
      El sábado, 17 de agosto de 2013 11:16:05 UTC+2, Javier Mediavilla Vegas escribió:
      > El viernes, 16 de agosto de 2013 19:15:36 UTC+2, Javier Mediavilla Vegas escribió:
      >
      > > Hi all,
      >
      > > Is there any command or any method that allows to include a file in the current file you are editing?
      >
      > >
      >
      > > By including a file I don't mean to read it with :read and paste it. I mean something like
      >
      > > \include{file}
      >
      > >
      >
      > > The semantic that I am looking can be (merely an example):
      >
      > > In normal mode, if some include is expanded, it deletes it contents and
      >
      > > replaces the \include statement
      >
      > >
      >
      > > In insert mode, when the cursor is hover the line the include is written, vim
      >
      > > reads the file, and copy its content to the line the statement was.
      >
      > >
      >
      > > Basically, I would like to have a conceal behaviour for such an order that loads a file as is in that moment so changes in the file included are reflected in the file that includes it.
      >
      > >
      >
      > > Thanks in advance,
      >
      > >
      >
      > > Regards,
      >
      > > Javier.
      >
      >
      >
      > Sorry for not putting an example.
      >
      > I want to achieve a latex like behaviour. For example:
      >
      >
      >
      > ---- snippet.txt ----
      >
      > this is a snippet
      >
      >
      >
      > ---- main.txt ----
      >
      > this is the main text
      >
      > \include{snippet.txt}
      >
      >
      >
      > So, If I hover the cursor over line 2 of main.txt in insert mode, vim substitutes \include{snippet.txt} by its contents.
      >
      >
      >
      > ---- main.txt ----
      >
      > this is the main text
      >
      > this is a snippet
      >
      >
      >
      > If I exit insert mode, the text becomes again as before, with \include. Suppose now I change the file snippet.txt to
      >
      >
      >
      > ---- snippet.txt ----
      >
      > this is a snippet
      >
      > added some new stuff
      >
      >
      >
      > Then, with main.txt opened, hover over \include{snippet.txt} to get
      >
      >
      >
      > ---- main.txt ----
      >
      > this is the main text
      >
      > this is a snippet
      >
      > added some new stuff
      >
      >
      >
      > When I change to normal mode, the file main.txt becomes to the original state, that is
      >
      >
      >
      > ---- main.txt ----
      >
      > this is the main text
      >
      > \include{snippet.txt}
      >
      >
      >
      > Cheers,
      >
      > Javier

      I read more carefully tim response, because I didn't get the first time. Folds could be a point buy I prefer that the action to be managed by vim so I don't have to care about that.

      --
      --
      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.
    • Christian Brabandt
      Hi Javier! ... Wouldn t that rather be annoying? Vim can t really do that and I doubt there exists an plugin that does that for you. There are too many
      Message 2 of 9 , Aug 17, 2013
      • 0 Attachment
        Hi Javier!

        On Sa, 17 Aug 2013, Javier Mediavilla Vegas wrote:

        > Sorry for not putting an example.
        > I want to achieve a latex like behaviour. For example:
        >
        > ---- snippet.txt ----
        > this is a snippet
        >
        > ---- main.txt ----
        > this is the main text
        > \include{snippet.txt}
        >
        > So, If I hover the cursor over line 2 of main.txt in insert mode, vim substitutes \include{snippet.txt} by its contents.
        >
        > ---- main.txt ----
        > this is the main text
        > this is a snippet
        >
        > If I exit insert mode, the text becomes again as before, with \include. Suppose now I change the file snippet.txt to
        >
        > ---- snippet.txt ----
        > this is a snippet
        > added some new stuff
        >
        > Then, with main.txt opened, hover over \include{snippet.txt} to get
        >
        > ---- main.txt ----
        > this is the main text
        > this is a snippet
        > added some new stuff
        >
        > When I change to normal mode, the file main.txt becomes to the original state, that is
        >
        > ---- main.txt ----
        > this is the main text
        > \include{snippet.txt}

        Wouldn't that rather be annoying?

        Vim can't really do that and I doubt there exists an plugin that does
        that for you. There are too many questions with this example, e.g. What
        happens, if you edit that snippet part, while in insert mode? How would
        Vim know, which part belongs to the snippet and which part it should
        keep in the main file?

        regards,
        Christian
        --

        --
        --
        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
        ... The original post had mentioned refreshing when folds were opened, so I assumed that you requested what you wanted. :-) I m not sure there s an easy way
        Message 3 of 9 , Aug 17, 2013
        • 0 Attachment
          On 2013-08-17 02:18, Javier Mediavilla Vegas wrote:
          > > ---- main.txt ----
          > >
          > > this is the main text
          > >
          > > \include{snippet.txt}
          >
          > I read more carefully tim response, because I didn't get the first
          > time. Folds could be a point buy I prefer that the action to be
          > managed by vim so I don't have to care about that.

          The original post had mentioned refreshing when folds were opened, so
          I assumed that you requested what you wanted. :-)

          I'm not sure there's an easy way for Vim to do this automatically (at
          least not without more overhead/testing than I'd be willing to give
          up). However, one could make a "update all my includes" mapping.

          Also note that you'd need to have markers bracketing both the start
          *and the end* of the included text so that it could be removed and
          replaced with new content. Otherwise, you'd not know where the
          inserted text ended. Thus, I might map something like

          :g/^\\include{.*}/+,/^% end include/-d|?\\include{.*}?|exec 'r
          '.substitute(getline('.'), '\\include{\([^}]*\)}', '\1', '')


          which finds everything from

          \\include{filename.txt}

          through a line starting with

          % end include

          (it looks like you're working in LaTeX, and a quick search suggests
          that this is how you do a single-line comment).

          Thus you could map a single key to update all the inclusions in your
          file.

          -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.
        • Javier Mediavilla Vegas
          ... Thanks for the help. That is what I wanted and I have learnt up some vim commands. Regards, Javier -- -- You received this message from the vim_use
          Message 4 of 9 , Aug 17, 2013
          • 0 Attachment
            El sábado, 17 de agosto de 2013 15:00:32 UTC+2, Tim Chase escribió:
            > On 2013-08-17 02:18, Javier Mediavilla Vegas wrote:
            >
            > > > ---- main.txt ----
            >
            > > >
            >
            > > > this is the main text
            >
            > > >
            >
            > > > \include{snippet.txt}
            >
            > >
            >
            > > I read more carefully tim response, because I didn't get the first
            >
            > > time. Folds could be a point buy I prefer that the action to be
            >
            > > managed by vim so I don't have to care about that.
            >
            >
            >
            > The original post had mentioned refreshing when folds were opened, so
            >
            > I assumed that you requested what you wanted. :-)
            >
            >
            >
            > I'm not sure there's an easy way for Vim to do this automatically (at
            >
            > least not without more overhead/testing than I'd be willing to give
            >
            > up). However, one could make a "update all my includes" mapping.
            >
            >
            >
            > Also note that you'd need to have markers bracketing both the start
            >
            > *and the end* of the included text so that it could be removed and
            >
            > replaced with new content. Otherwise, you'd not know where the
            >
            > inserted text ended. Thus, I might map something like
            >
            >
            >
            > :g/^\\include{.*}/+,/^% end include/-d|?\\include{.*}?|exec 'r
            >
            > '.substitute(getline('.'), '\\include{\([^}]*\)}', '\1', '')
            >
            >
            >
            >
            >
            > which finds everything from
            >
            >
            >
            > \\include{filename.txt}
            >
            >
            >
            > through a line starting with
            >
            >
            >
            > % end include
            >
            >
            >
            > (it looks like you're working in LaTeX, and a quick search suggests
            >
            > that this is how you do a single-line comment).
            >
            >
            >
            > Thus you could map a single key to update all the inclusions in your
            >
            > file.
            >
            >
            >
            > -tim

            Thanks for the help. That is what I wanted and I have learnt up some vim commands.

            Regards,
            Javier

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