使用:map
可提供Vim中的所有映射列表。但是,我无法搜索列表。我惊讶地看到它在一个不同类型的窗口中打开,不像通常的Vim帮助文件。有没有一种方法可以使它以通常的形式可用?
使用:map
可提供Vim中的所有映射列表。但是,我无法搜索列表。我惊讶地看到它在一个不同类型的窗口中打开,不像通常的Vim帮助文件。有没有一种方法可以使它以通常的形式可用?
Vim使用其内部分页程序来显示:map
的输出,其功能相当有限(有关详细信息,请参见:h pager
)。
如果您想在普通vim缓冲区中访问:map
的输出,可以使用:redir
:
:redir @a> " redirect output to register a
:map
:redir END
:put a " paste the output of :map in the current buffer
请注意,您可以将重定向到文件、变量等。有关更多详细信息,请参见:h redir
。
:h redir
for more details.)不要惊讶。 :map
和 :help
完全没有关系,因此没有任何理由期望它的工作方式像 :help
。
您可以给 :map
一个参数来缩小列表:
:map ,
通过正确配置wildmenu
和/或wildmode
,您可以使用Tab键补全:map
命令:
:map ,<Tab>
您还可以使用 <C-d>
列出当前映射:
:map <C-d>
您还可以使用特定于模式的 :map
变体来获取更可管理的列表::imap ,
:nmap ,
:xmap ,
and so on…
请注意,:map
只列出自定义映射(由您或插件创建的)。如果您想要默认映射列表,请查看:help index
。
---编辑---
因此,最近有人点赞了我这个老回答,事实证明在此期间添加了一个新命令:help :filter
来帮助处理这种用例。
您可以像这样使用它,只列出使用:help pumvisible()
的插入模式映射:
:filter pumvisible imap
虽然严格来说不是搜索功能,但这是一个非常有用的附加功能。
这里有一个强大的函数,可以创建一个可搜索的垂直分割,并带有排序后的:maps
输出结果。
function! s:ShowMaps()
let old_reg = getreg("a") " save the current content of register a
let old_reg_type = getregtype("a") " save the type of the register as well
try
redir @a " redirect output to register a
" Get the list of all key mappings silently, satisfy "Press ENTER to continue"
silent map | call feedkeys("\<CR>")
redir END " end output redirection
vnew " new buffer in vertical window
put a " put content of register
" Sort on 4th character column which is the key(s)
%!sort -k1.4,1.4
finally " Execute even if exception is raised
call setreg("a", old_reg, old_reg_type) " restore register a
endtry
endfunction
com! ShowMaps call s:ShowMaps() " Enable :ShowMaps to call the function
nnoremap \m :ShowMaps<CR> " Map keys to call the function
最后一行将两个键\m映射到调用该函数,您可以根据需要更改此内容。
sort --key=1,14
。 - JESii@a
赋值吗?为什么不能直接将 silent map | ...
的值放入新缓冲区中? - gentedbuiltin.keymaps
。
:redir
。+1 - Roman Kiselenko