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

Re: Go to start of visual selection

Expand Messages
  • Charles E Campbell Jr
    ... I m afraid that I don t understand your request. ctrl-v (move) o already puts the cursor into the upper left hand corner, assuming that you started with
    Message 1 of 14 , Feb 1, 2007
    View Source
    • 0 Attachment
      Andy Wokula wrote:

      > How can I move the cursor the start of the visual selection? With the
      > "o" command, yes. But how can I make sure the cursor is at the start
      > while visual mode is on? The "`<" motion followed by "gv" sets the
      > cursor back to the end if it was there.


      I'm afraid that I don't understand your request.

      ctrl-v (move) o

      already puts the cursor into the upper left hand corner, assuming that
      you started with the upper left hand corner.

      ctrl-v (move) o <esc> (move) gv

      also puts the cursor back into the upper left hand corner (same assumption).

      The "gv" already moves the cursor, so typing `< gv is the same as
      typing gv.

      If what you want is to

      ctrl-v (move) <esc> ... gv

      and have that end up with the cursor at the upper left hand corner, just
      follow it by an o ; ie.

      ctrl-v (move) <esc> ... gvo

      Regards,
      Chip Campbell
    • A.J.Mechelynck
      ... no, testing shows it s OK. I just hadn t noticed the _two_ mark jumps in these mappings. ... Best regards, Tony.
      Message 2 of 14 , Feb 1, 2007
      View Source
      • 0 Attachment
        Tim Chase wrote:
        >>> vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
        >>> vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
        >>>
        >>> which gives you a "Go to the Top" and "Go to the Bottom" mapping
        >>> within visual mode.
        >>
        >> Won't they move the boundary of the visual area together with the cursor?
        >
        > Not from my testing...
        >
        > [ed: a hush falls over the mailing-list...Tim actually tested this
        > response?! :) ]
        >
        > Perhaps a diff. setting between our setups if you're experiencing drifting?

        no, testing shows it's OK. I just hadn't noticed the _two_ mark jumps in these
        mappings.

        >
        > Other than the peculiar caveat regarding blockwise visual mode, it
        > worked for me. Even in blockwise mode, it successfully went to the top,
        > but wasn't always the top-*left* anchor.
        >
        > Note that the ">" and "<" marks are jumped-to with the back-tick (rather
        > than a regular apostrophe) which remembers column information as well,
        > so when "gt" is run/expanded/executed, it
        >
        > 1) leaves visual mode
        > 2) jumps to the exact anchor position of the bottom/top mark
        > 3) enters the previous visual-mode as returned by the visualmode() function
        > 4) and then jumps to the previous exact anchor position of the
        > top/bottom mark
        >
        > -tim
        >
        >
        >
        >
        >
        >
        >

        Best regards,
        Tony.
      • Bill McCarthy
        ... Why do you use ` instead of just `
        Message 3 of 14 , Feb 1, 2007
        View Source
        • 0 Attachment
          On Thu 1-Feb-07 11:51am -0600, Tim Chase wrote:

          > vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
          > vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>

          Why do you use `<lt> instead of just `< ? Just a matter of
          preference?

          --
          Best regards,
          Bill
        • Tim Chase
          ... Depending on what follows the `
          Message 4 of 14 , Feb 1, 2007
          View Source
          • 0 Attachment
            >> vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
            >> vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
            >
            > Why do you use `<lt> instead of just `< ? Just a matter of
            > preference?

            Depending on what follows the

            `<

            vim may try to interpret it as a character-notation. I prefer
            not to have to think about it, so just like with HTML entities
            when I write HTML, it's now hard-wired that, when writing
            mappings, I use <lt> (and I get stung enough with "|" vs. "<bar>"
            that I tend to err on the side of using the <> notation when I
            don't have to, just so I don't have to burn brain-cells thinking
            about it case-by-case.

            -tim
          • Yegappan Lakshmanan
            Hi Bill, ... The following text describing when to use in a map is taken from the Vim keymap tutorial which is available at:
            Message 5 of 14 , Feb 1, 2007
            View Source
            • 0 Attachment
              Hi Bill,

              On 2/1/07, Bill McCarthy <WJMc@...> wrote:
              > On Thu 1-Feb-07 11:51am -0600, Tim Chase wrote:
              >
              > > vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
              > > vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
              >
              > Why do you use `<lt> instead of just `< ? Just a matter of
              > preference?
              >

              The following text describing when to use <lt> in a map is taken
              from the Vim keymap tutorial which is available at:

              http://www.geocities.com/yegappan/vim_keymap.html

              ----------------------------------------------------------------------------------------------------
              When Vim parses a string in a map command, the \<...> sequence of characters is
              replaced by the corresponding control character. For example, let us
              say in insert
              mode you want the down arrow key to execute <C-N> when the insert complete
              popup menu is displayed. Otherwise, you want the down arrow key to move the
              cursor one line down. You can try the following command (which doesn't work):

              :inoremap <Down> <C-R>=pumvisible() ? "\<C-N>" : "\<Down>"<CR>

              When parsing the above command, Vim replaces <C-N> and <Down> with the
              corresponding control characters. When you press the down arrow in insert
              mode, as there are control characters in the expression now, the
              command will fail.

              To fix this, you should escape the "<" character, so that Vim will not
              replace "\<C-N>" with the control character when parsing the command. The
              following command works:

              :inoremap <Down> <C-R>=pumvisible() ? "\<lt>C-N>" : "\<lt>Down>"<CR>

              With the above command, Vim will use the control character only when the map
              is invoked and not when the above command is parsed.
              ------------------------------------------------------------------------------------------------------------


              ------------------------------------------------------------------------------------------------------------
              If the flag 'B' is present in 'cpoptions', then the backslash
              character is not treated
              as a special character in map commands. For example, let us say you want to
              create an insert-mode map for the <F6> key to insert the text "Press <Home> to
              go to first character". For this, you can try using the following command:

              imap <F6> Press <Home> to go to first character

              When you press <F6> in the insert mode, the <Home> in the above map will
              cause Vim to move the cursor to the first character in the line and insert the
              reminder of the text there. To literally enter the text "<Home>", you need
              to escape it:

              imap <F6> Press \<Home> to go to first character

              If the flag 'B' is not present in 'cpoptions', then the above map command will
              insert the correct text. If the flag 'B' is present, then the
              backslash character is
              not treated as a special character and the above map will not insert
              the correct
              text. To treat <Home> literally independent of the 'cpoptions' setting, you can
              use the following command:

              imap <F6> Press <lt>Home> to go to first character

              In the above command, the notation <lt> is used for "<" in "<Home>".
              ------------------------------------------------------------------------------------------------------------

              - Yegappan
            • Andy Wokula
              ... I don t understand why this works. There must be a difference between ` v` markers. Why
              Message 6 of 14 , Feb 4, 2007
              View Source
              • 0 Attachment
                Tim Chase schrieb:
                >> How can I move the cursor the start of the visual selection?
                >> With the "o" command, yes. But how can I make sure the cursor
                >> is at the start while visual mode is on? The "`<" motion
                >> followed by "gv" sets the cursor back to the end if it was
                >> there.
                >
                > I think it sounds like you want something like the following:
                >
                > vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
                > vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
                >
                > which gives you a "Go to the Top" and "Go to the Bottom" mapping within
                > visual mode.
                >
                > It can be a little funky in blockwise visual-mode, if your '< and '>
                > points are top-right and bottom-left (rather than top-left and
                > bottom-right), as the "top" will go to the top-right, not the top-left.
                > I haven't figured out a good way to do this without considerably more
                > code in the mapping (save the column of '< and then "gvO" to go back to
                > visual-mode but in the other corner and then compare the columns to see
                > which you want, perhaps needing to switch back...it's ugly).
                >
                > However, it should work fine in character-wise and line-wise visual modes.
                >
                > HTH,
                >
                > -tim

                I don't understand why this works.

                There must be a difference between
                `>v`<
                and
                :normal `>v`<

                "v" defines a new visual area and overwrites the `<,`> markers. Why
                does "`<" after ":normal" move the cursor to the start of the
                _previously_ selected visual area?

                Thx,
                Andy

                --
                kühl, @... ist wieder zurück

                EOF






                ___________________________________________________________
                Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de
              • Andy Wokula
                ... Works fine at least for character-wise visual mode, thanks! :-) IMHO, this little basic feature should be included in Vim. Regards, Andy -- EOF
                Message 7 of 14 , Feb 4, 2007
                View Source
                • 0 Attachment
                  Tim Chase schrieb:
                  >> How can I move the cursor the start of the visual selection?
                  >> With the "o" command, yes. But how can I make sure the cursor
                  >> is at the start while visual mode is on? The "`<" motion
                  >> followed by "gv" sets the cursor back to the end if it was
                  >> there.
                  >
                  > I think it sounds like you want something like the following:
                  >
                  > vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
                  > vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
                  >
                  > which gives you a "Go to the Top" and "Go to the Bottom" mapping within
                  > visual mode.
                  >
                  > It can be a little funky in blockwise visual-mode, if your '< and '>
                  > points are top-right and bottom-left (rather than top-left and
                  > bottom-right), as the "top" will go to the top-right, not the top-left.
                  > I haven't figured out a good way to do this without considerably more
                  > code in the mapping (save the column of '< and then "gvO" to go back to
                  > visual-mode but in the other corner and then compare the columns to see
                  > which you want, perhaps needing to switch back...it's ugly).
                  >
                  > However, it should work fine in character-wise and line-wise visual modes.
                  >
                  > HTH,
                  >
                  > -tim

                  Works fine at least for character-wise visual mode, thanks! :-)
                  IMHO, this little basic feature should be included in Vim.

                  Regards,
                  Andy

                  --
                  EOF




                  ___________________________________________________________
                  Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
                • Tim Chase
                  ... Sorry it s taken me a while to get back on this...life got a little crazy. Buried away in the help just above ... and in the section ... one finds this
                  Message 8 of 14 , Feb 6, 2007
                  View Source
                  • 0 Attachment
                    >> vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
                    >> vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
                    >
                    > I don't understand why this works.
                    >
                    > There must be a difference between
                    > `>v`<
                    > and
                    > :normal `>v`<
                    >
                    > "v" defines a new visual area and overwrites the `<,`>
                    > markers. Why does "`<" after ":normal" move the cursor to
                    > the start of the _previously_ selected visual area?

                    Sorry it's taken me a while to get back on this...life got a
                    little crazy.

                    Buried away in the help just above

                    :help :map-verbose

                    and in the section

                    :help map-listing

                    one finds this little morsel of help:

                    Note: When using mappings for Visual mode, you can use
                    the "'<" mark, which is the start of the last selected
                    Visual area in the current buffer |'<|.

                    It's also possible to read the help at

                    :help '<

                    either way, as it refers to the "last selected visual area"
                    which in visual-mode could mean either "the area selected
                    before the the one I'm currently in", or "the current visual
                    selection which is now the 'last selected visual area'
                    because I'm now doing something other than selecting". It
                    might help to have an extra sentence at this help to say
                    something like

                    If you are currently in visual mode, this refers to the
                    beginning/end of the *previous* visual selection

                    Hope this helps shed light on your question rather than
                    muddy the waters.

                    -tim
                  • Andy Wokula
                    ... Thanks for the pointer! I couldn t find hints about this in the help. Interesting that mappings for Visual mode include commands given with :normal
                    Message 9 of 14 , Feb 7, 2007
                    View Source
                    • 0 Attachment
                      Tim Chase schrieb:
                      > >> vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
                      > >> vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
                      > >
                      > > I don't understand why this works.
                      > >
                      > > There must be a difference between
                      > > `>v`<
                      > > and
                      > > :normal `>v`<
                      > >
                      > > "v" defines a new visual area and overwrites the `<,`>
                      > > markers. Why does "`<" after ":normal" move the cursor to
                      > > the start of the _previously_ selected visual area?
                      >
                      > Sorry it's taken me a while to get back on this...life got a
                      > little crazy.
                      >
                      > Buried away in the help just above
                      >
                      > :help :map-verbose
                      >
                      > and in the section
                      >
                      > :help map-listing
                      >
                      > one finds this little morsel of help:
                      >
                      > Note: When using mappings for Visual mode, you can use
                      > the "'<" mark, which is the start of the last selected
                      > Visual area in the current buffer |'<|.

                      Thanks for the pointer! I couldn't find hints about this in the help.

                      Interesting that "mappings for Visual mode" include commands given
                      with :normal (emphasize on "mappings").

                      > It's also possible to read the help at
                      >
                      > :help '<
                      >
                      > either way, as it refers to the "last selected visual area"
                      > which in visual-mode could mean either "the area selected
                      > before the the one I'm currently in", or "the current visual
                      > selection which is now the 'last selected visual area'
                      > because I'm now doing something other than selecting". It
                      > might help to have an extra sentence at this help to say
                      > something like
                      >
                      > If you are currently in visual mode, this refers to the
                      > beginning/end of the *previous* visual selection

                      This phrase would be more comprehensible, indeed.

                      > Hope this helps shed light on your question rather than
                      > muddy the waters.
                      >
                      > -tim

                      Most important: It turned out to be documented :-)

                      Regards,
                      Andy

                      --
                      EOF










                      ___________________________________________________________
                      Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de
                    • Andy Wokula
                      ... Ah, with a later Vim7 there is no difference any more. Obviously this has been fixed with patch 125, dated August 2006. Ok, this took three months till I
                      Message 10 of 14 , May 16, 2007
                      View Source
                      • 0 Attachment
                        Andy Wokula schrieb:
                        > Tim Chase schrieb:
                        >>> How can I move the cursor the start of the visual selection?
                        >>> With the "o" command, yes. But how can I make sure the cursor
                        >>> is at the start while visual mode is on? The "`<" motion
                        >>> followed by "gv" sets the cursor back to the end if it was
                        >>> there.
                        >>
                        >> I think it sounds like you want something like the following:
                        >>
                        >> vnoremap gt <esc>`>:exec 'norm '.visualmode().'`<lt>'<cr>
                        >> vnoremap gb <esc>`<lt>:exec 'norm '.visualmode().'`>'<cr>
                        >>
                        >> which gives you a "Go to the Top" and "Go to the Bottom" mapping
                        >> within visual mode.
                        >>
                        >> It can be a little funky in blockwise visual-mode, if your '< and '>
                        >> points are top-right and bottom-left (rather than top-left and
                        >> bottom-right), as the "top" will go to the top-right, not the
                        >> top-left. I haven't figured out a good way to do this without
                        >> considerably more code in the mapping (save the column of '< and then
                        >> "gvO" to go back to visual-mode but in the other corner and then
                        >> compare the columns to see which you want, perhaps needing to switch
                        >> back...it's ugly).
                        >>
                        >> However, it should work fine in character-wise and line-wise visual
                        >> modes.
                        >>
                        >> HTH,
                        >>
                        >> -tim
                        >
                        > I don't understand why this works.
                        >
                        > There must be a difference between
                        > `>v`<
                        > and
                        > :normal `>v`<
                        >
                        > "v" defines a new visual area and overwrites the `<,`> markers. Why
                        > does "`<" after ":normal" move the cursor to the start of the
                        > _previously_ selected visual area?
                        >
                        > Thx,
                        > Andy

                        Ah, with a later Vim7 there is no difference any more.
                        Obviously this has been fixed with patch 125, dated August 2006.
                        Ok, this took three months till I got it ...

                        --
                        Regards,
                        Andy
                      Your message has been successfully submitted and would be delivered to recipients shortly.