I would like to have the user call my function and then have the function request user input but I do not want the user to have to type 'enter' after typing a letter as is required by the "input()" function. For instance, the user should be able to type single letter commands like 'h','j','k','l' and each letter typed would loop around my function until the user typed 'x' for exit. If I use "input()" then the user would have to type 'h<enter>
','j<enter>
'...
Any suggestions on how I might be able to do this?
If more clarification is needed please let me know.
UPDATE
Got it working:
function! s:getchar()
let c = getchar()
if c =~ '^\d\+$'
let c = nr2char(c)
endif
return c
endfunction
" Interactively change the window size
function! InteractiveWindow()
let char = "s"
while char =~ '^\w$'
echo "(InteractiveWindow) TYPE: h,j,k,l to resize or a for auto resize"
let char = s:getchar()
if char == "h" | call SetWindowSize( "incr" ,-5 ,0 ) | endif
if char == "j" | call SetWindowSize( "incr" ,0 ,5 ) | endif
if char == "k" | call SetWindowSize( "incr" ,0 ,-5) | endif
if char == "l" | call SetWindowSize( "incr" ,5 ,0 ) | endif
if char == "a" | call SetWindowSize( "abs" ,0 ,0 ) | endif
redraw
endwhile
endfunction
getchar()
http://vimdoc.sourceforge.net/htmldoc/eval.html#getchar()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With