Skip to content

"maparg()" does not support the "!" mode #6118

@lacygoill

Description

@lacygoill

Describe the bug

You can't pass the pseudo-mode ! to maparg().

To Reproduce

Run this shell command:

vim -Nu NONE +'noremap! <c-a> <c-b>'

Run this Ex command:

:echo maparg('<c-a>', '!', 0, 1)

The output is an empty dictionary.

Expected behavior

The output is this dictionary:

{'lnum': 0, 'script': 0, 'simplified': 1, 'silent': 0, 'noremap': 1, 'lhs': '<C-A>', 'mode': '!', 'nowait': 0, 'expr': 0, 'sid': -3, 'rhs': '<c-b>', 'buffer': 0}

Environment

  • Vim version: 8.2 Included patches: 1-812
  • OS: Ubuntu 16.04.6 LTS
  • Terminal: XTerm(322)

Additional context

I think it's an omission because when reading :h maparg(), one can see that {mode} can be any mode used in a mapping command:

{mode} can be one of these strings:
        "n"	Normal
        "v"	Visual (including Select)
        "o"	Operator-pending
        "i"	Insert
        "c"	Cmd-line
        "s"	Select
        "x"	Visual
        "l"	langmap |language-mapping|
        "t"	Terminal-Job
        ""	Normal, Visual and Operator-pending
  • n = :nmap
  • v = :vmap
  • o = :omap
  • i = :imap
  • c = :cmap
  • s = :smap
  • x = :xmap
  • l = :lmap
  • t = :tmap
  • '' = :map

For each mapping command, there is a corresponding flag which can be passed as a second argument to maparg(). Except for the :map! command; there is no corresponding ! flag which could be passed to maparg().


Because of this, you can't use mapset() to restore a mapping installed via :map!.

vim -Nu NONE -S <(cat <<'EOF'
    noremap! X Y
    let save_map = maparg('X', '!', 0, 1)
    unmap! X
    call mapset('!', 0, 1)
    call feedkeys('iX')
EOF
)
# result:   'X' is inserted
# expected: 'Y' is inserted

That's because the first {mode} argument of mapset() is the same as for maparg():

{mode} and {abbr} should be the same as for the call to |maparg()|.

So, since ! can't be used for maparg(), it can't be used for mapset() either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions