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

Re: Go to start of visual selection

Expand Messages
  • 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 1 of 14 , Feb 1, 2007
      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 2 of 14 , Feb 4, 2007
        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 3 of 14 , Feb 4, 2007
          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 4 of 14 , Feb 6, 2007
            >> 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 5 of 14 , Feb 7, 2007
              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 6 of 14 , May 16, 2007
                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.