nvim-libmodal/examples/keymaps-manually.vim
Iron-E 49a02ad692
merge!: cleanup the plugin
This was my first plugin. Looking back on it, it was full of bad
design decisions (and I have elected to keep most of the user-facing
ones for backwards-compatability). This merge tries to uncrustify the
plugin by standardizing the documentation, removing much unecessary
code, reorganizing the internal structures, and removing references to
my own made-up terminology.
2022-04-25 17:59:33 -04:00

37 lines
1.0 KiB
VimL

" Keep track of the user's input history manually.
let s:inputHistory = []
" Clear the input history if it grows too long for our usage.
function! s:clear(indexToCheck) abort
if len(s:inputHistory) > a:indexToCheck
for i in range(len(s:inputHistory))
let s:inputHistory[i] = v:null
endfor
endif
endfunction
" This is the function that will be called whenever the user presses a button.
function! s:fooMode() abort
" Append to the input history, the latest button press.
let s:inputHistory = add(s:inputHistory, nr2char(g:fooModeInput)) " The input is a character number.
" Custom logic to test for each character index to see if it matches the 'zfo' mapping.
let l:index = 0
if s:inputHistory[0] == 'z'
if get(s:inputHistory, 1, v:null) == 'f'
if get(s:inputHistory, 2, v:null) == 'o'
echom 'It works!'
else
let l:index = 2
endif
else
let l:index = 1
endif
endif
call s:clear(l:index)
endfunction
" Enter the mode to begin the demo.
lua require('libmodal').mode.enter('FOO', 's:fooMode')