簡體   English   中英

如何在 Vim 映射列表中搜索?

[英]How to search in the Vim mapping listing?

使用: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

不要驚訝。 :map:help完全沒有關系所以沒有任何理由期望它像:help一樣工作。

你可以給:map一個參數來縮小列表的范圍:

:map ,

使用wildmenu和/或wildmode的正確值,您可以制表符完成:map

:map ,<Tab>

您還可以使用<Cd>列出當前映射:

:map <C-d>

您還可以使用:map的特定於模式的變體來獲得更易於管理的列表:

:imap ,
:nmap ,
:xmap ,
and so on…

但請記住, :map僅列出自定義映射(由您或您的插件制作)。 如果您需要默認映射列表,請查看:help index

這是一個強大的功能,可以使用: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以調用該函數,根據需要進行更改。

對於neovim,望遠鏡具有開箱即用的映射列表和搜索功能: builtin.keymaps

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM