Mercurial > vim
comparison runtime/doc/builtin.txt @ 28674:38f7a132bba3 v8.2.4861
patch 8.2.4861: it is not easy to restore saved mappings
Commit: https://github.com/vim/vim/commit/51d04d16f21e19d6eded98f9530d84089102f925
Author: Ernie Rael <errael@raelity.com>
Date: Wed May 4 15:40:22 2022 +0100
patch 8.2.4861: it is not easy to restore saved mappings
Problem: It is not easy to restore saved mappings.
Solution: Make mapset() accept a dict argument. (Ernie Rael, closes https://github.com/vim/vim/issues/10295)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 04 May 2022 16:45:03 +0200 |
parents | e4de5b5193b4 |
children | add09d468c0d |
comparison
equal
deleted
inserted
replaced
28673:1bb2e8f5cc4b | 28674:38f7a132bba3 |
---|---|
5308 "scriptversion" The version of the script. 999999 for | 5308 "scriptversion" The version of the script. 999999 for |
5309 |Vim9| script. | 5309 |Vim9| script. |
5310 "lnum" The line number in "sid", zero if unknown. | 5310 "lnum" The line number in "sid", zero if unknown. |
5311 "nowait" Do not wait for other, longer mappings. | 5311 "nowait" Do not wait for other, longer mappings. |
5312 (|:map-<nowait>|). | 5312 (|:map-<nowait>|). |
5313 "abbr" True if this is an |abbreviation|. | |
5313 | 5314 |
5314 The dictionary can be used to restore a mapping with | 5315 The dictionary can be used to restore a mapping with |
5315 |mapset()|. | 5316 |mapset()|. |
5316 | 5317 |
5317 The mappings local to the current buffer are checked first, | 5318 The mappings local to the current buffer are checked first, |
5378 unchanged. Items can still be changed by {expr2}, if you | 5379 unchanged. Items can still be changed by {expr2}, if you |
5379 don't want that use |deepcopy()| first. | 5380 don't want that use |deepcopy()| first. |
5380 | 5381 |
5381 | 5382 |
5382 mapset({mode}, {abbr}, {dict}) *mapset()* | 5383 mapset({mode}, {abbr}, {dict}) *mapset()* |
5383 Restore a mapping from a dictionary returned by |maparg()|. | 5384 mapset({dict}) |
5384 {mode} and {abbr} should be the same as for the call to | 5385 Restore a mapping from a dictionary, possibly returned by |
5385 |maparg()|. *E460* | 5386 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer |
5387 is true, is set on the current buffer; it is up to the caller | |
5388 to insure that the intended buffer is the current buffer. This | |
5389 feature allows copying mappings from one buffer to another. | |
5390 The dict.mode value may restore a single mapping that covers | |
5391 more than one mode, like with mode values of '!', ' ', 'nox', | |
5392 or 'v'. *E1276* | |
5393 | |
5394 In the first form, {mode} and {abbr} should be the same as | |
5395 for the call to |maparg()|. *E460* | |
5386 {mode} is used to define the mode in which the mapping is set, | 5396 {mode} is used to define the mode in which the mapping is set, |
5387 not the "mode" entry in {dict}. | 5397 not the "mode" entry in {dict}. |
5388 Example for saving and restoring a mapping: > | 5398 Example for saving and restoring a mapping: > |
5389 let save_map = maparg('K', 'n', 0, 1) | 5399 let save_map = maparg('K', 'n', 0, 1) |
5390 nnoremap K somethingelse | 5400 nnoremap K somethingelse |
5391 ... | 5401 ... |
5392 call mapset('n', 0, save_map) | 5402 call mapset('n', 0, save_map) |
5393 < Note that if you are going to replace a map in several modes, | 5403 < Note that if you are going to replace a map in several modes, |
5394 e.g. with `:map!`, you need to save the mapping for all of | 5404 e.g. with `:map!`, you need to save/restore the mapping for |
5395 them, since they can differ. | 5405 all of them, when they might differ. |
5406 | |
5407 In the second form, with {dict} as the only argument, mode | |
5408 and abbr are taken from the dict. | |
5409 Example: > | |
5410 vim9script | |
5411 var save_maps = maplist()->filter( | |
5412 (_, m) => m.lhs == 'K') | |
5413 nnoremap K somethingelse | |
5414 cnoremap K somethingelse2 | |
5415 # ... | |
5416 unmap K | |
5417 for d in save_maps | |
5418 mapset(d) | |
5419 endfor | |
5396 | 5420 |
5397 | 5421 |
5398 match({expr}, {pat} [, {start} [, {count}]]) *match()* | 5422 match({expr}, {pat} [, {start} [, {count}]]) *match()* |
5399 When {expr} is a |List| then this returns the index of the | 5423 When {expr} is a |List| then this returns the index of the |
5400 first item where {pat} matches. Each item is used as a | 5424 first item where {pat} matches. Each item is used as a |