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

Inserting text in front of multiple marked lines

Expand Messages
  • Matthias Pitzl
    Hello all! Perhaps this is a simple question but i m a bit confused. If i mark several lines with shift+v and then use shift+i to insert in front of the line,
    Message 1 of 7 , May 31, 2006
      Hello all!

      Perhaps this is a simple question but i'm a bit confused. If i mark
      several lines with shift+v and then use shift+i to insert in front of
      the line, the text entered is just placed in front of the first marked
      line. How can i easily add text to all marked lines?
      Thank you for your help!

      Sincerly,
      Matthias
    • Tim Chase
      ... It sounds like you re trying to do something allowed by blockwise visual mode from within linewise visual mode. As you ve found, it doesn t work in
      Message 2 of 7 , May 31, 2006
        > Perhaps this is a simple question but i'm a bit confused.
        > If i mark several lines with shift+v and then use shift+i
        > to insert in front of the line, the text entered is just
        > placed in front of the first marked line. How can i easily
        > add text to all marked lines?

        It sounds like you're trying to do something allowed by
        blockwise visual mode from within linewise visual mode. As
        you've found, it doesn't work in linewise. :)

        You can either select the range in blockwise mode (using
        ^V), or you can use an ex command.

        To learn more about the blockwise functionality, you can
        read at

        :help blockwise-operators

        If you want to insert text at the beginning of a range of
        lines, you can use

        :'<,'>s/^/text to insert

        If you have disjoint lines that can be found by a regexp,
        you can use

        :g/regexp/s/^/text to insert

        Often, for me, this "text to insert" is a "comment to end
        of line" specifier such as a "#" or "//".

        Just a few ideas,

        -tim
      • Matthias Pitzl
        Thank you for the fast answer Tim :) I ll take a look onto these help pages. The possibility with s/.../.../ i knew but i thought there has to be something
        Message 3 of 7 , May 31, 2006
          Thank you for the fast answer Tim :)
          I'll take a look onto these help pages. The possibility with s/.../.../
          i knew but i thought there has to be something easier ;)

          - Matthias

          Tim Chase wrote:
          > > Perhaps this is a simple question but i'm a bit confused.
          > > If i mark several lines with shift+v and then use shift+i
          > > to insert in front of the line, the text entered is just
          > > placed in front of the first marked line. How can i easily
          > > add text to all marked lines?
          >
          > It sounds like you're trying to do something allowed by
          > blockwise visual mode from within linewise visual mode. As
          > you've found, it doesn't work in linewise. :)
          >
          > You can either select the range in blockwise mode (using
          > ^V), or you can use an ex command.
          >
          > To learn more about the blockwise functionality, you can
          > read at
          >
          > :help blockwise-operators
          >
          > If you want to insert text at the beginning of a range of
          > lines, you can use
          >
          > :'<,'>s/^/text to insert
          >
          > If you have disjoint lines that can be found by a regexp,
          > you can use
          >
          > :g/regexp/s/^/text to insert
          >
          > Often, for me, this "text to insert" is a "comment to end
          > of line" specifier such as a "#" or "//".
          >
          > Just a few ideas,
          >
          > -tim
          >
          >
          >
          >
          >
        • Gary Johnson
          ... There is. You were close with your first try; you just missed a step. Mark the lines with shift+v, then type ctrl+v to change from linewise to blockwise,
          Message 4 of 7 , May 31, 2006
            On 2006-05-31, Matthias Pitzl <m.pitzl@...> wrote:

            > Tim Chase wrote:
            > > > Perhaps this is a simple question but i'm a bit confused.
            > > > If i mark several lines with shift+v and then use shift+i
            > > > to insert in front of the line, the text entered is just
            > > > placed in front of the first marked line. How can i easily
            > > > add text to all marked lines?
            > >
            > > It sounds like you're trying to do something allowed by
            > > blockwise visual mode from within linewise visual mode. As
            > > you've found, it doesn't work in linewise. :)
            > >
            > > You can either select the range in blockwise mode (using
            > > ^V), or you can use an ex command.
            > >
            > > To learn more about the blockwise functionality, you can
            > > read at
            > >
            > > :help blockwise-operators
            > >
            > > If you want to insert text at the beginning of a range of
            > > lines, you can use
            > >
            > > :'<,'>s/^/text to insert
            > >
            > > If you have disjoint lines that can be found by a regexp,
            > > you can use
            > >
            > > :g/regexp/s/^/text to insert
            > >
            > > Often, for me, this "text to insert" is a "comment to end
            > > of line" specifier such as a "#" or "//".
            > >
            > > Just a few ideas,

            > Thank you for the fast answer Tim :)
            > I'll take a look onto these help pages. The possibility with s/.../.../
            > i knew but i thought there has to be something easier ;)

            There is. You were close with your first try; you just missed a
            step. Mark the lines with shift+v, then type ctrl+v to change from
            linewise to blockwise, then type shift+i and type your text. When
            you then type escape, each line will have your text inserted in
            front of it.

            Gary

            --
            Gary Johnson | Agilent Technologies
            garyjohn@... | Wireless Division
            | Spokane, Washington, USA
          • Eric Leenman
            Hi, Is it possible to filter the :map output? For example to only show the mappings that have CTRL or
            Message 5 of 7 , May 31, 2006
              Hi,

              Is it possible to filter the :map output?
              For example to only show the mappings that have CTRL or <C- in it?

              Regards,
              Eric

              _________________________________________________________________
              Express yourself instantly with MSN Messenger! Download today - it's FREE!
              http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
            • Eric Arnold
              ... I don t think so, but you can :redir into a register, put into a buffer, or use split(), filter(), etc. I don t see a way to loop through the mappings
              Message 6 of 7 , Jun 1, 2006
                On 6/1/06, Eric Leenman <eric.leenman@...> wrote:
                > Hi,
                >
                > Is it possible to filter the :map output?
                > For example to only show the mappings that have CTRL or <C- in it?
                >

                I don't think so, but you can :redir into a register, put into a
                buffer, or use split(), filter(), etc. I don't see a way to loop
                through the mappings list directly from script.
              • Yakov Lerner
                ... You can try the ViewOutput plugin that puts such things a bit easier. (http://www.vim.org/scripts/script.php?script_id=897) ... Yakov
                Message 7 of 7 , Jun 3, 2006
                  On 6/1/06, Eric Leenman <eric.leenman@...> wrote:
                  > Is it possible to filter the :map output?
                  > For example to only show the mappings that have CTRL or <C- in it?

                  You can try the 'ViewOutput' plugin that puts such things a bit easier.
                  (http://www.vim.org/scripts/script.php?script_id=897)
                  If you download the viewoutput.vim , then:

                  :VO map " puts output of :map into new buffer
                  :v/<C-/d " or :g/<C-/p

                  Yakov
                Your message has been successfully submitted and would be delivered to recipients shortly.