vim脚本"input()"函数,不需要用户输入

ste*_*nmm 11 vim

我想让用户调用我的函数,然后让函数请求用户输入,但我不希望用户在键入"input()"函数所需的字母后输入'enter'.例如,用户应该能够键入单个字母命令,如'h','j','k','l',并且每个键入的字母都会围绕我的函数循环,直到用户输入'x'表示退出.如果我使用"input()"那么用户必须输入'h <enter>','j <enter>'......

有关我如何能够做到这一点的任何建议?

如果需要更多说明,请告诉我.

UPDATE

搞定了:

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
Run Code Online (Sandbox Code Playgroud)