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

When is map useful (as apposed to noremap)

Expand Messages
  • James Wood
    If I understand correctly, map commands (nmap, imap...) allow the resulting action to be affected by any other key bindings that happen to have been made. On
    Message 1 of 11 , May 7, 2014
    • 0 Attachment
      If I understand correctly, map commands (nmap, imap...) allow the resulting action to be affected by any other key bindings that happen to have been made. On the other hand, their noremap counterparts act as if no other mappings have been made. I can't think of any situations where one would want the result to be affected by other bindings, since this would be very hard to maintain. Are plain maps used much? Why?

      --
      --
      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/d/optout.
    • Elijah Griffin
      ... Plain maps are all you get in real vi, so people coming from that background will use them by default. Some other reasons: Making complex maps that can be
      Message 2 of 11 , May 7, 2014
      • 0 Attachment
        James Wood wrote:
        > If I understand correctly, map commands (nmap, imap...) allow the
        > resulting action to be affected by any other key bindings that happen to
        > have been made. On the other hand, their noremap counterparts act as if
        > no other mappings have been made. I can't think of any situations where
        > one would want the result to be affected by other bindings, since this
        > would be very hard to maintain. Are plain maps used much? Why?

        Plain maps are all you get in real vi, so people coming from that
        background will use them by default. Some other reasons:

        Making complex maps that can be tested piece by piece and then chained
        together.

        Making subroutine maps that can be called by other maps.

        Making maps that are recursive.

        Look at the toy macro sets that come with vim. Towers of Hanoi, eg:

        " to set the height of the tower, change the digit in the following
        " two lines to the height you want (select from 1 to 9)
        map t 7
        map! t 7

        That's using a map as a variable. Then later in the macro set it gets used
        like this:

        "delete more than height-of-tower characters
        map q tllD

        Elijah

        --
        --
        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/d/optout.
      • Gary Johnson
        ... I don t know whether plain maps are used much, but here is one example of their use from my ~/.vimrc. For the changelog.vim filetype plugin: Don t
        Message 3 of 11 , May 7, 2014
        • 0 Attachment
          On 2014-05-07, James Wood wrote:
          > If I understand correctly, map commands (nmap, imap...) allow the
          > resulting action to be affected by any other key bindings that
          > happen to have been made. On the other hand, their noremap
          > counterparts act as if no other mappings have been made. I can't
          > think of any situations where one would want the result to be
          > affected by other bindings, since this would be very hard to
          > maintain. Are plain maps used much? Why?

          I don't know whether plain maps are used much, but here is one
          example of their use from my ~/.vimrc.


          " For the changelog.vim filetype plugin:
          "
          " Don't source it right away, but do so upon the Changelog
          " opening mapping. This will also source our customizations
          " ahead of it.
          "
          nmap <silent> <Leader>o :runtime! ftplugin/changelog.vim<CR><Leader>o


          I wanted to have the <Leader>o mapping from the changelog.vim plugin
          open a changelog file as it does after the plugin is sourced, but I
          didn't want to source the plugin every time I opened Vim, partly as
          a matter of principle and partly because of the time required by my
          ~/.vim/ftplugin/changelog.vim to find the appropriate changelog file.

          Regards,
          Gary

          --
          --
          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/d/optout.
        • Erik Christiansen
          ... Trying :h map! , I find no words describing what the ! does to map. Scanning all of map.txt for map! , no further clue was revealed. Scanning all of
          Message 4 of 11 , May 8, 2014
          • 0 Attachment
            On 07.05.14 18:26, Elijah Griffin wrote:
            > map t 7
            > map! t 7

            Trying ":h map!", I find no words describing what the '!' does to map.

            Scanning all of map.txt for "map!", no further clue was revealed.
            Scanning all of map.txt for "!", its indicator meaning in a "map-listing"
            was revealed, but still no description of what it might do in the other
            context.

            Trying ":h !" just finds: *:!cmd* *:!*

            There is a table at "*mapmode-ic* *mapmode-i* *mapmode-c* *mapmode-l*",
            which includes:

            commands: modes:
            Insert Command-line Lang-Arg
            :map! :noremap! :unmap! :mapclear! yes yes -

            but that omits "map", so it does not help to infer what '!' does to
            "map". ("map" appears in the "*map-overview* *map-modes*" table, but
            that is an orthogonal view, allowing no comparison with "map!")

            The search was first conducted in 7.3, but I've just built 7.4, with the
            same results.

            Is there any way to find an explanation of the effect of the modifier,
            in the help?

            Erik

            --
            The UN also estimates that the current global population of 7.2 billion will
            reach 9.6 billion by 2050. That is a faster rate of growth than previously
            estimated. - http://www.bbc.co.uk/news/world-asia-22907307

            --
            --
            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/d/optout.
          • Nikolay Pavlov
            ... Unlike most other commands bang in :map! is not a modifier. :map! to :map is the same as :vmap to :map, just with different set of modes. It is listed in
            Message 5 of 11 , May 8, 2014
            • 0 Attachment


              On May 8, 2014 5:36 PM, "Erik Christiansen" <dvalin@...> wrote:
              >
              > On 07.05.14 18:26, Elijah Griffin wrote:
              > >       map t 7
              > >       map! t 7
              >
              > Trying ":h map!", I find no words describing what the '!' does to map.
              >
              > Scanning all of map.txt for "map!", no further clue was revealed.
              > Scanning all of map.txt for "!", its indicator meaning in a "map-listing"
              > was revealed, but still no description of what it might do in the other
              > context.
              >
              > Trying ":h !" just finds:   *:!cmd* *:!*
              >
              > There is a table at "*mapmode-ic* *mapmode-i* *mapmode-c* *mapmode-l*",
              > which includes:
              >
              >     commands:                                 modes:
              >                                           Insert  Command-line  Lang-Arg
              > :map!  :noremap!  :unmap!  :mapclear!       yes        yes         -
              >
              > but that omits "map", so it does not help to infer what '!' does to
              > "map". ("map" appears in the "*map-overview* *map-modes*" table, but
              > that is an orthogonal view, allowing no comparison with "map!")
              >
              > The search was first conducted in 7.3, but I've just built 7.4, with the
              > same results.
              >
              > Is there any way to find an explanation of the effect of the modifier,
              > in the help?

              Unlike most other commands bang in :map! is not a modifier. :map! to :map is the same as :vmap to :map, just with different set of modes. It is listed in :h :map as a separate entity that is linked to :h mapmode-ic.

              Note that technically it is a modifier: there is no :map! command. But this does not matter: unless you are a Vim developer you should treat this as a separate command.

              >
              > Erik
              >
              > --
              > The UN also estimates that the current global population of 7.2 billion will
              > reach 9.6 billion by 2050. That is a faster rate of growth than previously
              > estimated.  - http://www.bbc.co.uk/news/world-asia-22907307
              >
              > --
              > --
              > 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/d/optout.

              --
              --
              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/d/optout.
            • Elijah Griffin
              ... Some commands work both in Insert mode and Command-line mode, some not: commands: modes: Insert Command-line Lang-Arg ...
              Message 6 of 11 , May 8, 2014
              • 0 Attachment
                Nikolay Pavlov wrote:
                > On May 8, 2014 5:36 PM, "Erik Christiansen" <dvalin@...> wrote:
                >> Trying ":h map!", I find no words describing what the '!' does to map.
                >> Scanning all of map.txt for "map!", no further clue was revealed.

                I see this in map.txt:
                ------ cut 8<------
                Some commands work both in Insert mode and Command-line mode, some not:

                commands: modes:
                Insert Command-line Lang-Arg
                :map! :noremap! :unmap! :mapclear! yes yes -
                ------ cut 8<------

                The ! addon to map comes from original vi, where the distinction is
                "map" works during vi expects commands, and "map!" works when vi is
                not expecting commands (including the ex ":" line).

                Back in the dark days when you had to create your own mappings for
                arrow keys, you would usually have slightly different ones for "map"
                and "map!", eg:

                " <esc>OD is left arrow (xterm)
                " <esc>OC is right arrow (xterm)
                " During insert, hitting escape leaves you one position
                " to the left of where you were, so left action is just
                " <esc> then insert, while right requires moving two
                " positions before returning to insert.
                " All ^[ are meant to indicate literal <esc>apes.
                map ^[OD j
                map! ^[OD ^[i
                map ^[OC l
                map! ^[OC ^[2li

                > Unlike most other commands bang in :map! is not a modifier. :map! to :map
                > is the same as :vmap to :map, just with different set of modes. It is
                > listed in :h :map as a separate entity that is linked to :h mapmode-ic.

                Another way to think about map! is that in runs in the same context as
                abbreviations, but without all the weirdness of abbreviations: maps
                with multicharacter left-hand-sides (lhs) run when the sequence is
                entered fast enough; abbreviations have no timeout, but wait for an
                additional character that indicates a break has been reached. Maps
                will recurse, abbreviations will not. The rhs of an abbreviation will
                be checked for maps, however.

                Elijah
                ------
                considers himself vi expert, but only vim proficient

                --
                --
                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/d/optout.
              • Erik Christiansen
                ... Elijah, thank you for the explanation, especially that map! exists for hysterical raisins. Lacking any direct comparison in the help, the two replies and
                Message 7 of 11 , May 9, 2014
                • 0 Attachment
                  On 08.05.14 14:10, Elijah Griffin wrote:
                  > I see this in map.txt:
                  > ------ cut 8<------
                  > Some commands work both in Insert mode and Command-line mode, some not:
                  >
                  > commands: modes:
                  > Insert Command-line Lang-Arg
                  > :map! :noremap! :unmap! :mapclear! yes yes -
                  > ------ cut 8<------
                  >
                  > The ! addon to map comes from original vi, where the distinction is
                  > "map" works during vi expects commands, and "map!" works when vi is
                  > not expecting commands (including the ex ":" line).

                  Elijah, thank you for the explanation, especially that map! exists for
                  hysterical raisins. Lacking any direct comparison in the help, the two
                  replies and scrolling up and down and around in the help has led me to
                  form the tentative view that the various disjoint tables do not offer an
                  integrated view of mapping, and the real Overview lies in *map-listing*.
                  If <Space> == " map" in that list, then all the other tables serve only
                  to confuse by needlessly fragmenting the picture, AFAICT.

                  FWIW, I think that it would be possible to respect the holy 80 column
                  limit, yet present one table providing a complete Overview at
                  *map-overview*, not just the present partial thing, if the "modes:"
                  headings were changed to "I C L N V S O P", with preceding expansions of
                  same. Entries need only be "y" or "-".

                  ...

                  > Another way to think about map! is that in runs in the same context as
                  > abbreviations, but without all the weirdness of abbreviations: maps
                  > with multicharacter left-hand-sides (lhs) run when the sequence is
                  > entered fast enough; abbreviations have no timeout, but wait for an
                  > additional character that indicates a break has been reached. Maps
                  > will recurse, abbreviations will not. The rhs of an abbreviation will
                  > be checked for maps, however.

                  Not being a table-driven state machine, I find that such descriptions of
                  _what_ should happen foster easy adoption of a simple abstract view,
                  whereas a sprinkling of discontiguous tables showing partial views of
                  _how_ stuff behaves to be the string of pearls broken and rolling on the
                  floor.

                  But taking the list at *map-listing* to be the true Overview, I can save
                  a week of scrolling about various tables, and immediately see:

                  map = nmap + vmap + smap + omap
                  map! = imap + cmap

                  If a LHS column were added to that list, adding the corresponding ?map
                  on each line, then it would be a much better Overview for the Vim help
                  than is currently present. It would then also be explicit that <Space>
                  means "map".

                  Erik


                  --
                  Rising levels of CO2 around the world will significantly impact the nutrient
                  content of crops according to a new study. Experiments show levels of zinc, iron
                  and protein are likely to be reduced by up to 10% in wheat and rice by 2050.
                  - http://www.bbc.com/news/science-environment-27308720

                  --
                  --
                  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/d/optout.
                • Christian Brabandt
                  Hi Erik! ... Well, patches are welcome ;) Best, Christian -- Frauen, seid lieber schön als klug - Männer können besser gucken als denken. -- -- You received
                  Message 8 of 11 , May 9, 2014
                  • 0 Attachment
                    Hi Erik!

                    On Fr, 09 Mai 2014, Erik Christiansen wrote:

                    > On 08.05.14 14:10, Elijah Griffin wrote:
                    > > I see this in map.txt:
                    > > ------ cut 8<------
                    > > Some commands work both in Insert mode and Command-line mode, some not:
                    > >
                    > > commands: modes:
                    > > Insert Command-line Lang-Arg
                    > > :map! :noremap! :unmap! :mapclear! yes yes -
                    > > ------ cut 8<------
                    > >
                    > > The ! addon to map comes from original vi, where the distinction is
                    > > "map" works during vi expects commands, and "map!" works when vi is
                    > > not expecting commands (including the ex ":" line).
                    >
                    > Elijah, thank you for the explanation, especially that map! exists for
                    > hysterical raisins. Lacking any direct comparison in the help, the two
                    > replies and scrolling up and down and around in the help has led me to
                    > form the tentative view that the various disjoint tables do not offer an
                    > integrated view of mapping, and the real Overview lies in *map-listing*.
                    > If <Space> == " map" in that list, then all the other tables serve only
                    > to confuse by needlessly fragmenting the picture, AFAICT.
                    >
                    > FWIW, I think that it would be possible to respect the holy 80 column
                    > limit, yet present one table providing a complete Overview at
                    > *map-overview*, not just the present partial thing, if the "modes:"
                    > headings were changed to "I C L N V S O P", with preceding expansions of
                    > same. Entries need only be "y" or "-".
                    >
                    > ...
                    >
                    > > Another way to think about map! is that in runs in the same context as
                    > > abbreviations, but without all the weirdness of abbreviations: maps
                    > > with multicharacter left-hand-sides (lhs) run when the sequence is
                    > > entered fast enough; abbreviations have no timeout, but wait for an
                    > > additional character that indicates a break has been reached. Maps
                    > > will recurse, abbreviations will not. The rhs of an abbreviation will
                    > > be checked for maps, however.
                    >
                    > Not being a table-driven state machine, I find that such descriptions of
                    > _what_ should happen foster easy adoption of a simple abstract view,
                    > whereas a sprinkling of discontiguous tables showing partial views of
                    > _how_ stuff behaves to be the string of pearls broken and rolling on the
                    > floor.
                    >
                    > But taking the list at *map-listing* to be the true Overview, I can save
                    > a week of scrolling about various tables, and immediately see:
                    >
                    > map = nmap + vmap + smap + omap
                    > map! = imap + cmap
                    >
                    > If a LHS column were added to that list, adding the corresponding ?map
                    > on each line, then it would be a much better Overview for the Vim help
                    > than is currently present. It would then also be explicit that <Space>
                    > means "map".

                    Well, patches are welcome ;)

                    Best,
                    Christian
                    --
                    Frauen, seid lieber schön als klug - Männer können besser gucken als denken.

                    --
                    --
                    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/d/optout.
                  • ZyX
                    ... One of the worst layout you can choose for plain text. Compare ... with ... 1. Does not require you to see column header. Your requires to constantly
                    Message 9 of 11 , May 9, 2014
                    • 0 Attachment
                      > FWIW, I think that it would be possible to respect the holy 80 column
                      > limit, yet present one table providing a complete Overview at
                      > *map-overview*, not just the present partial thing, if the "modes:"
                      > headings were changed to "I C L N V S O P", with preceding expansions of
                      > same. Entries need only be "y" or "-".

                      One of the worst layout you can choose for plain text. Compare

                      > | I C L N X S O
                      > map | N X S O
                      > nmap | N
                      > vmap | X S
                      > xmap | X
                      > smap | S
                      > omap | O
                      > map! | I C
                      > imap | I
                      > lmap | * * L
                      > cmap | C

                      with

                      > | I C L N X S O
                      > map | - - - y y y y
                      > nmap | - - - y - - -
                      > vmap | - - - - y y -
                      > xmap | - - - - y - -
                      > smap | - - - - - y -
                      > omap | - - - - - - y
                      > map! | y y - - - - -
                      > imap | y - - - - - -
                      > lmap | * * y - - - -
                      > cmap | - y - - - - -

                      : first (my)

                      1. Does not require you to see column header. Your requires to constantly
                      eye-scroll up to determine what `y`s refer to.
                      2. Is still readable if font is not fixed width.
                      3. Is still readable if you rearrange lines: putting `nmap` at the end makes it
                      hard to use this table because there are too much dashes between both start
                      and end.

                      PS: previous two messages are probably my messages, but I did not delete them.
                      They were deleted after the following sequence of actions:

                      1. Write some message from Google Groups web interface.
                      2. Reply to the previously written message to post some text I forgot to post.

                      Third deleted message appeared after step 1.

                      --
                      --
                      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/d/optout.
                    • Erik Christiansen
                      On 09.05.14 10:50, ZyX wrote: ... OK, OK, OK, OK, extending/merging the current format is suboptimal. The table is just narrow enough for your proposal to work
                      Message 10 of 11 , May 10, 2014
                      • 0 Attachment
                        On 09.05.14 10:50, ZyX wrote:
                        Erik wrote:
                        > > FWIW, I think that it would be possible to respect the holy 80 column
                        > > limit, yet present one table providing a complete Overview at
                        > > *map-overview*, not just the present partial thing, if the "modes:"
                        > > headings were changed to "I C L N V S O P", with preceding expansions of
                        > > same. Entries need only be "y" or "-".
                        >
                        > One of the worst layout you can choose for plain text.

                        OK, OK, OK, OK, extending/merging the current format is suboptimal.
                        The table is just narrow enough for your proposal to work - mostly.

                        However, the proposal that I preferred in that post was providing
                        consistency with the table at *map-listing*. E.g:

                        -----------------------------------------------------------------
                        COMMAND ACTIVE MODES
                        -----------------------------------------------------------------
                        :map :noremap Normal, Visual, Select, Operator-pending
                        :nmap :nnoremap Normal
                        :vmap :vnoremap Visual and Select
                        :smap :snoremap Select
                        :xmap :xnoremap Visual
                        :omap :onoremap Operator-pending
                        :map! :noremap! Insert and Command-line
                        :imap :inoremap Insert
                        :lmap :lnoremap Insert, Command-line, Lang-Arg
                        :cmap :cnoremap Command-line
                        -----------------------------------------------------------------
                        The active modes for each [ iclnxso]unmap and [ iclnxso]mapclear
                        is the same as its map. Ditto for :unmap! and :mapclear!
                        -----------------------------------------------------------------
                        (:nunmap can also be used outside a monastery.)

                        Now we aren't scrolling back and forth between three tables, with some
                        overlaps, but mostly just unhelpful fragmentation of what should have
                        been one overview. (Last line preserved with a minor correction.)
                        And understanding gleaned from one table applies to the other, without
                        the need for mental gymnastics.

                        Erik

                        --
                        Suburbia is where the developer bulldozes out the trees, then names
                        the streets after them. - Bill Vaughn

                        --
                        --
                        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/d/optout.
                      • Erik Christiansen
                        ... Thank you for the encouragement, Christian. I ll see if we can reach agreement on a way forward. Might as well grab what input is on offer, while we have
                        Message 11 of 11 , May 10, 2014
                        • 0 Attachment
                          On 09.05.14 11:19, Christian Brabandt wrote:
                          > Well, patches are welcome ;)

                          Thank you for the encouragement, Christian. I'll see if we can reach
                          agreement on a way forward. Might as well grab what input is on offer,
                          while we have this iron in the fire.

                          Is "diff -u" the preferred patch type?

                          Erik

                          --
                          manual, n.:
                          A unit of documentation. There are always three or more on a given item.
                          One is on the shelf; someone has the others.
                          The information you need is in the others. - Ray Simard

                          --
                          --
                          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/d/optout.
                        Your message has been successfully submitted and would be delivered to recipients shortly.