From a84c18f7aba0f411f08bcc3de7459f17b9824633 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 2 Sep 2019 21:44:54 +0200 Subject: [PATCH] [nvim] Add function to show all keymappings Use :ShowMaps to display all currently mapped things for vim. Will not include things like `i`, but actual mappings. --- .config/nvim/init.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index cebfcf9..85dced0 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -358,6 +358,26 @@ call matchadd('ColorColumn', '\%81v', 100) " KEYBINDINGS {{{ " ================================================================================ " +" Show all mapped keys in a list - from https://stackoverflow.com/questions/13990136/display-a-ordered-vim-keyboard-mapping +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("\") + 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 +" use :ShowMaps to call the function +com! ShowMaps call s:ShowMaps() " Enable :ShowMaps to call the function + " set our leader key to space since with hjkl, space is largely useless let mapleader = "\" " maps the leader for buffer local mappings (e.g. vim-waikiki for files under