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

substituting only in visual block

Expand Messages
  • Dr. Johannes Zellner
    Hi, having marked a visual block with ctrl-v, I d like to so a search / replace only in that visual block. E.g. when selecting the right block in: xx xx xx xx
    Message 1 of 11 , Aug 1, 2006
    • 0 Attachment
      Hi,

      having marked a visual block with ctrl-v, I'd like to so a search /
      replace only in that visual block. E.g. when selecting the right block
      in:

      xx xx
      xx xx
      xx xx
      xx xx

      I'd to do something like s/xx/yy/g which applies only to the selected
      block. How can I do this?

      --
      Johannes
    • Bernd Strohhäcker
      ... Hi, try Charles Campell s vis-script: http://www.vim.org/scripts/script.php?script_id=1195 HTH, Bernd
      Message 2 of 11 , Aug 1, 2006
      • 0 Attachment
        Dr. Johannes Zellner schrieb:
        > Hi,
        >
        > having marked a visual block with ctrl-v, I'd like to so a search /
        > replace only in that visual block. E.g. when selecting the right block
        > in:
        >
        > xx xx
        > xx xx
        > xx xx
        > xx xx
        >
        > I'd to do something like s/xx/yy/g which applies only to the selected
        > block. How can I do this?
        >
        >
        Hi,

        try Charles Campell's vis-script:
        http://www.vim.org/scripts/script.php?script_id=1195

        HTH, Bernd
      • John Orr
        Hi, I m wondering if anyone has a good solution to an annoying problem I seem to cause myself. When you type a command in vim that results in text scrolling up
        Message 3 of 11 , Aug 2, 2006
        • 0 Attachment
          Hi,

          I'm wondering if anyone has a good solution to an annoying problem I seem to cause myself.

          When you type a command in vim that results in text scrolling up the screen - eg :messages or :registers, you will be hit by one of two comments:
          Press ENTER or type command to continue

          OR

          -- More --

          depending upon whether there are more lines to display. Often, I want to good way to immediately go back to editing from either of these situations.

          To quit the "more" situation, pressing "q" seems to be a good option. It will also appear to work for the "Press ENTER or type a command" situation, in that it appears to be a command which in turn clears the text.

          However, in the "Press ENTER" situation, that q will be remembered as the start of a command. If you then go to give another colon command - the command line window will open (no matter how long you wait it seems).

          The command line window opens in normal mode, not insert mode - which means the command I've just started typing doesn't register - and this, fundamentally, is the problem I'd like to solve. All solutions considered.

          One would be to press escape instead of q - it works for both situations above - but it's much more of a finger-stretch than pressing q. (A lesser but slightly annoying problem is that it causes my visual bell to fire in the "Press Enter" situation, since we're already in normal mode.)

          I tried the option from the vim help in the cmdline.txt file
          :au CmdwinEnter * startinsert

          but this doesn't seem to work fully - at least the first character I type is always missed (using vim 7 with patches 1-42).

          I'd be very grateful to hear how other people execute the task of telling vim "okay, I've read enough info from that command - get rid of it now please".

          Thanks,
          John
        • Robert Cussons
          ... Thanks for the pointer to this, it is a useful script, if Charles is out there today, just a little point, it doesn t seem to like c being used in
          Message 4 of 11 , Aug 2, 2006
          • 0 Attachment
            Bernd Strohhäcker wrote:
            > Dr. Johannes Zellner schrieb:
            >
            >> Hi,
            >>
            >> having marked a visual block with ctrl-v, I'd like to so a search /
            >> replace only in that visual block. E.g. when selecting the right block
            >> in:
            >>
            >> xx xx
            >> xx xx
            >> xx xx
            >> xx xx
            >>
            >> I'd to do something like s/xx/yy/g which applies only to the selected
            >> block. How can I do this?
            >>
            >>
            >
            > Hi,
            >
            > try Charles Campell's vis-script:
            > http://www.vim.org/scripts/script.php?script_id=1195
            >
            > HTH, Bernd
            >

            Thanks for the pointer to this, it is a useful script, if Charles is out
            there today, just a little point, it doesn't seem to like 'c' being used
            in substitutions, don't know if you already new about that. But perhaps
            I should give an example, if I have the text below, with the two columns
            under fh in the top line highlighted, so the 6th and 7th character in
            each line highlighted:

            sdasdfhafdlhasdf
            dsfhalshdflkashf

            adfhalasdfhasdfl
            asdfhaldfhlsadhf

            sahdflakshfdl


            then I use the command:

            :'<,'>B s/l/m/g

            I get the result:

            sdasdfhafdlhasdf
            dsfhamshdflkashf

            adfhamasdfhasdfl
            asdfhamdfhlsadhf

            sahdfmakshfdl

            as you would expect, all l's in these two columns have been changed to
            m's. Now I do the same but I want to be prompted:

            :'<,'>B s/l/m/gc

            but this time I get this result:

            sdasdafdlhasdf
            dsfhahdflkashf

            adfhasdfhasdfl
            asdfhdfhlsadhf

            sahdfkshfdl
            fh
            ls

            la
            al

            la

            Thanks for the script though Charles, I look forward to using it.
            Rob.
          • Yakov Lerner
            ... Then you can use q safely for both Press Enter prompt and for More prompt. Does this help ? Yakov
            Message 5 of 11 , Aug 2, 2006
            • 0 Attachment
              On 8/2/06, John Orr <john.orr@...> wrote:
              > When you type a command in vim that results in text scrolling up the screen - eg :messages or :registers, you will be hit by one of two comments:
              > Press ENTER or type command to continue
              >
              > OR
              >
              > -- More --
              >
              > depending upon whether there are more lines to display. Often, I want to good way to immediately go back to editing from either of these situations.
              >
              > To quit the "more" situation, pressing "q" seems to be a good option. It will also appear to work for the "Press ENTER or type a command" situation, in that it appears to be a command which in turn clears the text.
              >
              > However, in the "Press ENTER" situation, that q will be remembered as the start of a command.

              How about remapping normal-mode q to nop:
              :nmap q <nop>
              Then you can use q safely for both 'Press Enter' prompt and for 'More' prompt.
              Does this help ?

              Yakov
            • Yakov Lerner
              ... I retract my q mapping. It would make any normal-mode command involving q imopssible. Not good. Another solution would be to remap Esc in normal mode ...
              Message 6 of 11 , Aug 2, 2006
              • 0 Attachment
                On 8/2/06, Yakov Lerner <iler.ml@...> wrote:
                > On 8/2/06, John Orr <john.orr@...> wrote:
                > > When you type a command in vim that results in text scrolling up the screen - eg :messages or :registers, you will be hit by one of two comments:
                > > Press ENTER or type command to continue
                > >
                > > OR
                > >
                > > -- More --
                > >
                > > depending upon whether there are more lines to display. Often, I want to good way to immediately go back to editing from either of these situations.
                > >
                > > To quit the "more" situation, pressing "q" seems to be a good option. It will also appear to work for the "Press ENTER or type a command" situation, in that it appears to be a command which in turn clears the text.
                > >
                > > However, in the "Press ENTER" situation, that q will be remembered as the start of a command.
                >
                > How about remapping normal-mode q to nop:
                > :nmap q <nop>
                > Then you can use q safely for both 'Press Enter' prompt and for 'More' prompt.
                > Does this help ?

                I retract my q mapping. It would make any normal-mode command
                involving q imopssible. Not good.

                Another solution would be to remap Esc in normal mode
                to suppress its visual bell:

                :nmap <esc> <nop>

                This does not make Escape key nearer, but it gets rid of
                visual bell when you use Esc in response to 'Press Enter'.

                Regarding remote nature of Esc key, I solved it for myself by
                I using mini-keyboard, 28x10cm. I love it. Everything is nearer
                on such keyboard, fingers need to travel less. I heard other people
                remap Esc key to some other less distant key.

                Yakov

                Yakov
              • striker
                What version of Vim are you using? In version 7.0 on both Windows and OS X, highlighting the region and doing :s/x/y/g works fine. Kevin
                Message 7 of 11 , Aug 2, 2006
                • 0 Attachment
                  What version of Vim are you using? In version 7.0 on both Windows
                  and OS X, highlighting the region and doing :s/x/y/g works fine.
                  Kevin


                  On Aug 2, 2006, at 2:23 AM, Bernd Strohhäcker wrote:

                  > Dr. Johannes Zellner schrieb:
                  >> Hi,
                  >>
                  >> having marked a visual block with ctrl-v, I'd like to so a search /
                  >> replace only in that visual block. E.g. when selecting the right
                  >> block
                  >> in:
                  >>
                  >> xx xx
                  >> xx xx
                  >> xx xx
                  >> xx xx
                  >>
                  >> I'd to do something like s/xx/yy/g which applies only to the selected
                  >> block. How can I do this?
                  >>
                  >>
                  > Hi,
                  >
                  > try Charles Campell's vis-script: http://www.vim.org/scripts/
                  > script.php?script_id=1195
                  >
                  > HTH, Bernd
                  >
                • A.J.Mechelynck
                  ... yes, linewise (with
                  Message 8 of 11 , Aug 2, 2006
                  • 0 Attachment
                    striker wrote:
                    > What version of Vim are you using? In version 7.0 on both Windows and
                    > OS X, highlighting the region and doing :s/x/y/g works fine.
                    > Kevin

                    yes, linewise (with '<,'> auto inserted after : ). But blockwise?

                    >
                    >
                    > On Aug 2, 2006, at 2:23 AM, Bernd Strohhäcker wrote:
                    >
                    >> Dr. Johannes Zellner schrieb:
                    >>> Hi,
                    >>>
                    >>> having marked a visual block with ctrl-v, I'd like to so a search /
                    >>> replace only in that visual block. E.g. when selecting the right block
                    >>> in:
                    >>>
                    >>> xx xx
                    >>> xx xx
                    >>> xx xx
                    >>> xx xx
                    >>>
                    >>> I'd to do something like s/xx/yy/g which applies only to the selected
                    >>> block. How can I do this?
                    >>>
                    >>>
                    >> Hi,
                    >>
                    >> try Charles Campell's vis-script:
                    >> http://www.vim.org/scripts/script.php?script_id=1195
                    >>
                    >> HTH, Bernd
                    >>
                    >
                    >
                    >
                    >

                    Best regards,
                    Tony.
                  • Charles E Campbell Jr
                    ... (messages somewhat abbreviated above) The selected column does show up separately for a bit; however, when one is done answering y or n (etc), the
                    Message 9 of 11 , Aug 2, 2006
                    • 0 Attachment
                      Robert Cussons wrote:

                      > Bernd Strohhäcker wrote:
                      >
                      >> try Charles Campell's vis-script:
                      >> http://www.vim.org/scripts/script.php?script_id=1195
                      >
                      > Thanks for the pointer to this, it is a useful script, if Charles is
                      > out there today, just a little point, it doesn't seem to like 'c'
                      > being used in substitutions, don't know if you already new about that...


                      (messages somewhat abbreviated above)

                      The selected column does show up separately for a bit; however, when one
                      is done answering "y" or "n"
                      (etc), the amended column does get put back -- ie. the confirmed
                      substitution works. That behavior is
                      fundamental to how vis.vim works. It isolates the requested text block,
                      performs the operation, and inserts
                      the text block back.

                      Regards,
                      Chip Campbell
                    • Yakov Lerner
                      ... Wow. Cute trick. I wondered how it is possible to do block-scoped substitution at all. Yakov
                      Message 10 of 11 , Aug 2, 2006
                      • 0 Attachment
                        On 8/2/06, Charles E Campbell Jr <drchip@...> wrote:
                        > Robert Cussons wrote:
                        >
                        > > Bernd Strohhäcker wrote:
                        > >
                        > >> try Charles Campell's vis-script:
                        > >> http://www.vim.org/scripts/script.php?script_id=1195
                        > >
                        > > Thanks for the pointer to this, it is a useful script, if Charles is
                        > > out there today, just a little point, it doesn't seem to like 'c'
                        > > being used in substitutions, don't know if you already new about that...
                        >
                        >
                        > (messages somewhat abbreviated above)
                        >
                        > The selected column does show up separately for a bit; however, when one
                        > is done answering "y" or "n"
                        > (etc), the amended column does get put back -- ie. the confirmed
                        > substitution works. That behavior is
                        > fundamental to how vis.vim works. It isolates the requested text block,
                        > performs the operation, and inserts
                        > the text block back.

                        Wow. Cute trick. I wondered how it is possible
                        to do block-scoped substitution at all.

                        Yakov
                      • John Orr
                        Thanks Yakov, and others for the Escape substitute ideas. I ll probably try a few of them. John
                        Message 11 of 11 , Aug 2, 2006
                        • 0 Attachment
                          Thanks Yakov, and others for the Escape substitute ideas. I'll probably try a few of them.
                          John

                          On Wednesday 02 August 2006 19:13, Yakov Lerner wrote:
                          > On 8/2/06, Yakov Lerner <iler.ml@...> wrote:
                          > > On 8/2/06, John Orr <john.orr@...> wrote:
                          > > > When you type a command in vim that results in text scrolling up the screen - eg :messages or :registers, you will be hit by one of two comments:
                          > > > Press ENTER or type command to continue
                          > > >
                          > > > OR
                          > > >
                          > > > -- More --
                          > > >
                          > > > depending upon whether there are more lines to display. Often, I want to good way to immediately go back to editing from either of these situations.
                          > > >
                          > > > To quit the "more" situation, pressing "q" seems to be a good option. It will also appear to work for the "Press ENTER or type a command" situation, in that it appears to be a command which in turn clears the text.
                          > > >
                          > > > However, in the "Press ENTER" situation, that q will be remembered as the start of a command.
                          > >
                          > Another solution would be to remap Esc in normal mode
                          > to suppress its visual bell:
                          >
                          > :nmap <esc> <nop>
                          >
                          > This does not make Escape key nearer, but it gets rid of
                          > visual bell when you use Esc in response to 'Press Enter'.
                          >
                          > Regarding remote nature of Esc key, I solved it for myself by
                          > I using mini-keyboard, 28x10cm. I love it. Everything is nearer
                          > on such keyboard, fingers need to travel less. I heard other people
                          > remap Esc key to some other less distant key.
                          >
                          > Yakov
                          >
                          > Yakov
                          >
                        Your message has been successfully submitted and would be delivered to recipients shortly.