开发者

vim script "input()" function that doesn't require user to hit enter

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 s开发者_如何学编程hould 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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜