I am having a text file where I have a cheat sheet of commands I learned. When pressing some key ,it should be displayed in popup window. In Kakoune editor they display a help using Alt+i , like that I want to show my cheatsheet in popup windows.

As i am learning VIM recently , this sheet might be helpful in reminding the commands. How to do it via vimrc? My cheatsheet is copied in ~/.vim_cheatsheet. I am using Vim 8.2

  • Please, be specific, if the question is about Vim or Neovim. These two are very different programs, especially concerning popup window implementation.
    – Matt
    Nov 9 '20 at 13:17
  • @Matt Oh.. That difference also there . I did not think that. So some plugin which can do show a help file in popup window this can be achievable. isn't it ? Nov 9 '20 at 13:39

I've done something similar before. I was learning Vim's fold commands. I just stuffed my cheat sheet in a string that separated each line with a comma...

let g:foldcmds = split("zf  (Plus a motion) Operator to create a fold.,zF   Create a fold for [count] lines.  Works like zf.,zd Delete one fold at the cursor.,zD   Delete folds recursively at the cursor.,zE  Eliminate all folds in the window.,zo   Open one fold under the cursor.,",',')

(That's an abbreviated version.)

Alternatively, read the cheatsheet from a file:

let g:foldcmds = readfile('/path/to/file')

Each line in the file will get a line in the popup.

You'd call it like this for example...

:call popup_create(g:foldcmds, #{ title: ' Fold Commands  ', 
    padding: [0,1,0,1], border: [], filter: 'popup_filter_yesno', close: 'click' })

Then I stuck it in a mapping...

nnoremap <silent> <leader>z :call popup_create(g:foldcmds, #{ title: ' Fold Commands  ', 
    padding: [0,1,0,1], border: [], filter: 'popup_filter_yesno' })<CR>


enter image description here

Hit Esc or X to exit.

  • I am not good at vimscript. Can I show my file contents line by line in popup window? Nov 9 '20 at 10:58
  • It displays error as below Error detected while processing /root/.vimrc: line 1: E484: Can't open file ~/vimcheatsheet line 3: E723: Missing end of Dictionary '}': E116: Invalid arguments for function popup_create line 4: E492: Not an editor command: padding: [0,1,0,1], border: [], filter: 'popup_filter_yesno', close: 'click' }) Nov 9 '20 at 11:57
  • Put popup/mapping commands on a single line. They're only split up above for readabililty.
    – B Layer
    Nov 9 '20 at 12:01
  • It still says E484: Can't open file ~/vimcheatsheet . I even did chmod 777 to that file Nov 9 '20 at 12:14
  • 1
    To use ~ you may have to do readfile(expand('~/filename')). (Or just use full path like I said.)
    – B Layer
    Nov 9 '20 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.