简体   繁体   中英

Vim command to introspectively list available commands

It would help me a lot to be able to view a list of Vim commands, and related metadata (eg. a description of each command, if it has aliases, etc.).

I understand that, through Vim plugins, the list of commands can be extended, and also depending on what options Vim was compiled with, can change the list of available commands.

I've done extensive searches online, for things like "vim command to list commands," but have come up empty-handed. The only command lists I can find are static documentation, that don't take into account the version of Vim you're running (including Neovim), what plugins you have installed / enabled, and what options Vim was compiled with.

Question : Is there a Vim command that introspectively lists all of the available commands in Vim?

In searchInRuntime I've the following function that list all commands starting with a leading text (that could be empty). This is an old trick to get what vim would expand through command line completion -- :h c_CTRL-A .

" s:MatchingCommands(ArgLead)                              {{{3
" return the list of custom commands starting by {FirstLetters}
function! s:MatchingCommands(ArgLead)
  silent! exe "norm! :".a:ArgLead."\<c-a>\"\<home>let\ cmds=\"\<cr>"
  let cmds = substitute(cmds, '\s\+', '\n', 'g')
  " for your purpose, split is probably more fit
  return cmds
endfunction

Note that it can't know what the commands are meant for. At best, you can fetch the definition of user commands thanks execute('verbose command '.cmdname) ( execute() is a very recent function).

Note by the way that unlike execute('command') , this solution also list standard commands, not just user defined commands.

Regarding other actions available in vim (in case you weren't just looking for vim commands ), while we can list user defined mappings (even may be even know that they do when they rely on well named plug-mappings), there is no way to list any other actions like dd , J ...

Learn how to look up commands and navigate the built-in :help (there's automatic completion, listing of all candidates with Ctrl + A , and so on); it is comprehensive and also offers many tips. Most (good) plugins also provide their own help pages, so I think that answers your question best.

Don't try to implement some sort of introspection (as one commenter remarked to "shoot yourself in the foot"); rather, use the existing facilities of Vim. You can even write your own documentation pages (under ~/.vim/doc/*.txt) ; that's what I do: Collect tips, and short clips from other help locations. And it offers a place to document some older plugins that don't have their own help page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM