nvim-libmodal/examples/keymaps-manually.vim

37 lines
1.0 KiB
VimL
Raw Normal View History

2020-08-27 16:10:01 +00:00
" Keep track of the user's input history manually.
2020-08-26 22:26:11 +00:00
let s:inputHistory = []
2020-08-27 16:10:01 +00:00
" Clear the input history if it grows too long for our usage.
2020-08-26 22:26:11 +00:00
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
2020-08-27 16:10:01 +00:00
" This is the function that will be called whenever the user presses a button.
2020-08-26 22:26:11 +00:00
function! s:fooMode() abort
2020-08-27 16:10:01 +00:00
" Append to the input history, the latest button press.
let s:inputHistory = add(s:inputHistory, nr2char(g:fooModeInput)) " The input is a character number.
2020-08-26 22:26:11 +00:00
2020-08-27 16:10:01 +00:00
" Custom logic to test for each character index to see if it matches the 'zfo' mapping.
2020-08-26 22:26:11 +00:00
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
2020-08-27 16:10:01 +00:00
" Enter the mode to begin the demo.
2020-08-26 22:26:11 +00:00
lua require('libmodal').mode.enter('FOO', 's:fooMode')