简体   繁体   English

Vim命令内省地列出可用命令

[英]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.). 能够查看Vim命令列表和相关元数据(例如,每个命令的描述,是否具有别名等)将对我有很大帮助。

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. 我知道,通过Vim插件,可以扩展命令列表,并且根据Vim编译时使用的选项,可以更改可用命令的列表。

I've done extensive searches online, for things like "vim command to list commands," but have come up empty-handed. 我已经在网上进行了广泛的搜索,例如“ vim命令列出命令”,但是空手而归。 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. 我能找到的唯一命令列表是静态文档,没有考虑您正在运行的Vim的版本(包括Neovim),已安装/启用的插件以及使用Vim编译的选项。

Question : Is there a Vim command that introspectively lists all of the available commands in Vim? 问题 :是否有一个Vim命令内省地列出Vim中所有可用的命令?

In searchInRuntime I've the following function that list all commands starting with a leading text (that could be empty). 在searchInRuntime中,我具有以下函数,该函数列出了所有以前导文本(可以为空)开头的命令。 This is an old trick to get what vim would expand through command line completion -- :h c_CTRL-A . 这是获取vim通过命令行完成功能扩展的老技巧- :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). 充其量,您可以通过execute('verbose command '.cmdname)获取用户命令的定义( execute()是一个非常新的函数)。

Note by the way that unlike execute('command') , this solution also list standard commands, not just user defined commands. 请注意,与execute('command') ,此解决方案还列出了标准命令,而不仅是用户定义的命令。

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 ... 关于vim中可用的其他操作(以防您不只是在寻找vim 命令 ),尽管我们可以列出用户定义的映射(甚至可能甚至知道它们在依赖命名插件映射时也会这样做),但是没有列出ddJ ...

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); 了解如何查找命令并浏览内置的:help (自动完成功能,使用Ctrl + A列出所有候选对象,等等); 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. 而是使用Vim的现有功能。 You can even write your own documentation pages (under ~/.vim/doc/*.txt) ; 您甚至可以编写自己的文档页面(在~/.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. 它提供了一个地方来记录一些没有自己的帮助页面的较旧的插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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