Skip to content

Add descriptions to commands via vim.api.nvim_create_user_command #2076

@mrjones2014

Description

@mrjones2014

Is your feature request related to a problem? Please describe.

Trying to build a good legendary.nvim extension for nvim-tree.lua

Describe the solution you'd like

You create the commands here:

local function setup_vim_commands()
vim.api.nvim_create_user_command("NvimTreeOpen", function(res)
require("nvim-tree.api").tree.open { path = res.args }
end, { nargs = "?", complete = "dir" })
vim.api.nvim_create_user_command("NvimTreeClose", function()
require("nvim-tree.api").tree.close()
end, { bar = true })
vim.api.nvim_create_user_command("NvimTreeToggle", function(res)
require("nvim-tree.api").tree.toggle { find_file = false, focus = true, path = res.args, update_root = false }
end, { nargs = "?", complete = "dir" })
vim.api.nvim_create_user_command("NvimTreeFocus", function()
require("nvim-tree.api").tree.focus()
end, { bar = true })
vim.api.nvim_create_user_command("NvimTreeRefresh", function()
require("nvim-tree.api").tree.reload()
end, { bar = true })
vim.api.nvim_create_user_command("NvimTreeClipboard", function()
require("nvim-tree.api").fs.print_clipboard()
end, { bar = true })
vim.api.nvim_create_user_command("NvimTreeFindFile", function(res)
require("nvim-tree.api").tree.find_file { open = true, update_root = res.bang }
end, { bang = true, bar = true })
vim.api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
require("nvim-tree.api").tree.toggle { find_file = true, focus = true, path = res.args, update_root = res.bang }
end, { bang = true, nargs = "?", complete = "dir" })
vim.api.nvim_create_user_command("NvimTreeResize", function(res)
M.resize(res.args)
end, { nargs = 1, bar = true })
vim.api.nvim_create_user_command("NvimTreeCollapse", function()
require("nvim-tree.api").tree.collapse_all(false)
end, { bar = true })
vim.api.nvim_create_user_command("NvimTreeCollapseKeepBuffers", function()
require("nvim-tree.api").tree.collapse_all(true)
end, { bar = true })
vim.api.nvim_create_user_command("NvimTreeGenerateOnAttach", keymap_legacy.cmd_generate_on_attach, {})
end

The vim.api.nvim_create_user_command function accepts a desc field to provide a description that will be shown if you look up the commands via the Neovim API.

Describe alternatives you've considered

Hard-coding the descriptions.

Additional context

mrjones2014/legendary.nvim#320

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions