Thursday, May 8, 2014

Re: What does ! do to map? [Was: When is map useful (as apposed to noremap)]

Nikolay Pavlov wrote:
> On May 8, 2014 5:36 PM, "Erik Christiansen" <dvalin@internode.on.net> 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@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: