How to know the details of an keymap's content if it is created by vim.keymap.set

Defining a keymap via vim.keymap.set

local function dog() end
vim.keymap.set('n', '<Leader>dog', dog)

then :redir > keymap.txt | nmap | redir END will output all the normal keymaps.

Then I find that in keymap.txt

n  <Space>pc   * <Cmd>lua require("conf.builtin_extend").ping_cursor()<CR>
n  <Space>dog  * <Lua function 3>
n  <Space>tc   * :tabclose<CR>

The keymaps defined via vimL is practical useful: I know the content of a keymap/what it is doing.
But I completely don’t know what <Leader>dog is doing as it is only showing me a lua function.

In pratical use, I use Telescope keymaps to quickly find the keymaps I want (if forget the keymap but remember what it does). And now with the new API it is not easy to do that.

1 Like

Lua functions don’t have a (useful) string representation. Use the desc key in the options table of vim.keymap.set to set a human-readable description of the keymap.

vim.keymap.set('n', '<Leader>dog', dog, { desc = "Do something dog like" }
1 Like

This is very useful, but looking at :h vim.keymap.set, I can’t find any references to this desc field.

Is it missing, or did I just fail to see it?

It’s referenced here:

{opts} table A table of :map-arguments such as
“silent”. In addition to the options listed in
, this table also accepts the
following keys:

1 Like

Ah, my bad, I’d only followed the reference to :map-argument, but not to nvim_set_keymap().