comparison runtime/doc/builtin.txt @ 28817:1ad71fcbf546 v8.2.4932

patch 8.2.4932: not easy to filter the output of maplist() Commit: https://github.com/vim/vim/commit/d8f5f766219273a8579947cc80b92580b6988a4b Author: Ernie Rael <errael@raelity.com> Date: Tue May 10 17:50:39 2022 +0100 patch 8.2.4932: not easy to filter the output of maplist() Problem: Not easy to filter the output of maplist(). Solution: Add mode_bits to the dictionary. (Ernie Rael, closes https://github.com/vim/vim/issues/10356)
author Bram Moolenaar <Bram@vim.org>
date Tue, 10 May 2022 19:00:04 +0200
parents 0f0fed554cdc
children b5c46d447518
comparison
equal deleted inserted replaced
28816:708dfad50c43 28817:1ad71fcbf546
5329 |Vim9| script. 5329 |Vim9| script.
5330 "lnum" The line number in "sid", zero if unknown. 5330 "lnum" The line number in "sid", zero if unknown.
5331 "nowait" Do not wait for other, longer mappings. 5331 "nowait" Do not wait for other, longer mappings.
5332 (|:map-<nowait>|). 5332 (|:map-<nowait>|).
5333 "abbr" True if this is an abbreviation |abbreviations|. 5333 "abbr" True if this is an abbreviation |abbreviations|.
5334 "mode_bits" Vim's internal binary representation of "mode".
5335 |mapset()| ignores this; only "mode" is used.
5336 See |maplist()| for usage examples. The values
5337 are from src/vim.h and may change in the future.
5334 5338
5335 The dictionary can be used to restore a mapping with 5339 The dictionary can be used to restore a mapping with
5336 |mapset()|. 5340 |mapset()|.
5337 5341
5338 The mappings local to the current buffer are checked first, 5342 The mappings local to the current buffer are checked first,
5389 5393
5390 Example to show all mappings with 'MultiMatch' in rhs: > 5394 Example to show all mappings with 'MultiMatch' in rhs: >
5391 vim9script 5395 vim9script
5392 echo maplist()->filter( 5396 echo maplist()->filter(
5393 (_, m) => match(m.rhs, 'MultiMatch') >= 0) 5397 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
5398 < It can be tricky to find mappings for particular |:map-modes|.
5399 |mapping-dict|'s "mode_bits" can simplify this. For example,
5400 the mode_bits for Normal, Insert or Command-line modes are
5401 0x19. To find all the mappings available in those modes you
5402 can do: >
5403 vim9script
5404 var saved_maps = []
5405 for m in maplist()
5406 if and(m.mode_bits, 0x19) != 0
5407 saved_maps->add(m)
5408 endif
5409 endfor
5410 echo saved_maps->mapnew((_, m) => m.lhs)
5411 < The values of the mode_bits are defined in Vim's src/vim.h
5412 file and they can be discovered at runtime using
5413 |:map-commands| and "maplist()". Example: >
5414 vim9script
5415 omap xyzzy <Nop>
5416 var op_bit = maplist()->filter(
5417 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5418 ounmap xyzzy
5419 echo printf("Operator-pending mode bit: 0x%x", op_bit)
5394 5420
5395 5421
5396 mapnew({expr1}, {expr2}) *mapnew()* 5422 mapnew({expr1}, {expr2}) *mapnew()*
5397 Like |map()| but instead of replacing items in {expr1} a new 5423 Like |map()| but instead of replacing items in {expr1} a new
5398 List or Dictionary is created and returned. {expr1} remains 5424 List or Dictionary is created and returned. {expr1} remains