Skip to main content
show how to read froma file
Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59

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>

Result:

enter image description here

Hit Esc or X to exit.

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.)

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>

Result:

enter image description here

Hit Esc or X to exit.

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>

Result:

enter image description here

Hit Esc or X to exit.

Source Link
B Layer
  • 20.1k
  • 2
  • 32
  • 59

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.)

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>

Result:

enter image description here

Hit Esc or X to exit.