Describe the bug
maparg() with the {dict} arugment does not include a script key.
To Reproduce
Run this shell command:
vim -Nu NONE +'nno <script> <c-a> <c-b>'
Then this Ex command:
:echo maparg('<c-a>', 'n', 0, 1)->keys()
The list does not contain the script key.
Expected behavior
The list does contain the script key.
Environment
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
I've also noticed that the pseudo-key <SID> is not translated in the rhs key when the {dict} argument is true. However, it is translated when {dict} is omitted or false.
I know that this is to be expected, because it seems to be documented:
The returned String has special characters translated like in the output of the ":map" command listing.
...
"rhs" The {rhs} of the mapping as typed.
However, I would argue that the translation is more useful when you want to save/restore a mapping; would it be possible to either:
<SID> in the rhs keyrhs_translated?) where <SID> is translatedI know it's currently doable via a substitute() call and using the value stored in the sid key, but it would make the process easier (and maybe more reliable).
Thank you for the comment. Also, forget about <SID>, I think one can just invoke maparg() twice:
:echo extend(maparg('cd', 'n', 0, 1), {'rhs': escape(maparg('cd', 'n'), '|')})
—
You are receiving this because you commented.
In the todo list, there is this item:
maparg() does not show the <script> flag. When temporarily changing a
mapping, how to restore the script ID?
As of 8.2.0855, you can determine whether a mapping was defined with the <script> argument via the script key:
:nno <c-a> <c-a>
:echo maparg('<c-a>', 'n', 0, 1).script
0
:nno <script> <c-b> <c-b>
:echo maparg('<c-b>', 'n', 0, 1).script
1
Similarly, you can get the script ID via the sid key:
vim -Nu NONE -S <(cat <<'EOF'
nno <c-b> :call <sid>func()<cr>
fu s:func()
endfu
EOF
)
:echo maparg('<c-b>', 'n', 0, 1).sid
1
And you can get the rhs of the mapping in a form where the pseudo-key <sid> is translated, provided you don't pass the optional {dict} argument to maparg():
vim -Nu NONE -S <(cat <<'EOF'
nno <c-b> :call <sid>func()<cr>
fu s:func()
endfu
EOF
)
:echo maparg('<c-b>', 'n')
:call <SNR>1_func()<CR>
^^^^^^^
And we now have mapset() to restore a mapping.
So I think the item is no longer relevant.
—
You are receiving this because you commented.
Thanks for checking. I'll remove the entry from the todo list.
There are a few more remarks about maparg(), is any of those obsolete, or needs adjustment now?
—
You are receiving this because you commented.
I haven't found anything obvious, but I've noticed this item:
- <C--> cannot be mapped. Should be possible to recognize this as a
normal "-" with the Ctrl modifier.
As of 8.2.0862, it seems to work in the GUI, and in xterm when modifyOtherKeys is enabled.
There's also this sentence:
Even better: add a way to disable a mapping temporarily and re-enable it later.
Not sure whether it should be removed or updated, now that we have mapset().
—
You are receiving this because you commented.