vim 脚本“input()"不需要用户按回车键的功能 [英] vim script "input()" function that doesn't require user to hit enter
问题描述
我想让用户调用我的函数,然后让函数请求用户输入,但我不希望用户在输入input()"函数所需的字母后必须输入enter".例如,用户应该能够输入诸如h"、j"、k"、l"之类的单字母命令,并且键入的每个字母都会围绕我的函数循环,直到用户键入x"退出.如果我使用input()",那么用户将不得不输入'h
','j
'...
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.
更新
开始工作:
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()
这篇关于vim 脚本“input()"不需要用户按回车键的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!