[英]How to find all vim mappings starting with “control key”?
In vim: 在vim中:
:map
list all key mappings :map
列出所有键映射 :map {lhs}
list all key mappings for the key sequences starting with {lhs}. :map {lhs}
列出所有以{lhs}开头的键序列的键映射。 How do you seach for "all key mappings starting with the control key" ? 您如何寻找“所有从控制键开始的键映射”?
(I know I can still list all mappings, redirect the output to a file and grep; but it is not very efficient). (我知道我仍然可以列出所有映射,将输出重定向到文件和grep;但这不是很有效)。
Thanks ! 谢谢 !
No, there's no direct, built-in, method for that. 不,没有直接的内置方法。
What you can do instead is: 您可以做的是:
:redir @a redirect output of next command to register a
:map list mappings
:redir END end redirection
:vnew edit new buffer in vertical window
:put a put content of register a
:v/<C-/d delete all lines not matching '<C-'
Which you could turn easily into a function. 您可以轻松地将其转换为功能。
If you want a sorted, searchable list of :maps
output in which to search for <C-
, you can do the following: 如果需要
:maps
输出的可搜索列表,可在其中搜索<C-
,则可以执行以下操作:
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
This is a robust function to create a vertical split with the sorted output of :maps
. 这是一个强大的功能,可使用
:maps
的排序输出创建垂直拆分。 I put it in my vimrc
. 我把它放在了
vimrc
。
The last line maps the two keys \\ m to call the function, change this as you wish. 最后一行映射两个键\\ m以调用该函数,并根据需要更改它。
Note: This will will not include vim's default commands like Ctrl-a to increment a number, as they are not made with map
. 注意:这将不包括vim的默认命令(如Ctrl-a)来增加数字,因为它们不是使用
map
。 See :help index
for these. 请参阅
:help index
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.