Reputation:
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?
Upvotes: 2
Views: 3184
Reputation: 32966
getcompletion('', 'command')
will return the list of all known commands. Even, user-defined commands. To filter commands that match a given pattern, use that pattern as the first parameter.
Before Vim 7.4.2011, we had to play with c_CTRL-A
as described below.
In searchInRuntime I've the following function that lists 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 lists 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
...
Upvotes: 2
Reputation: 172758
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.
Upvotes: 1