打开后获取用户输入 window
Get user input after opening window
如何在打开新的 window(其中包含项目)后获取用户输入(以便我可以过滤某些项目)?我想要类似于 CtrlP or CtrlSpace 的东西。我试图查看他们的代码,但未能确定他们在哪里做的。
我调用它的方式是创建一个 command
调用函数 foo
打开 window 并等待用户输入。
我已经尝试了一些变化(foo
内的代码):
botright split NewWindow
let input = input('>> ')
和
botright split NewWindow
redraw!
let input = input('>> ')
第一个总是在打开新 window 之前让我输入。在它们两个中, >>
部分都没有出现(输入本身也没有)。他们怎么做到的?一堆 getchar
个电话?
(使用 Neovim v0.2.0)
好的。似乎并没有那么困难(由于某种原因我迷失在源代码中而看不到它)。他们基本上一次得到一个字符并不断回显结果。
据我所知,CtrlP 使用了以下方法:
- 重画
- 用
getchar()
求字符
- 将字符与累加器字符串连接起来
- 回显字符串
- 想循环就循环
我的 vimscript 现在看起来像这样:
let str = ''
while s:some_stop_condition()
redraw
let c = getchar()
let str = str . nr2char(c)
echo str
endwhile
如何在打开新的 window(其中包含项目)后获取用户输入(以便我可以过滤某些项目)?我想要类似于 CtrlP or CtrlSpace 的东西。我试图查看他们的代码,但未能确定他们在哪里做的。
我调用它的方式是创建一个 command
调用函数 foo
打开 window 并等待用户输入。
我已经尝试了一些变化(foo
内的代码):
botright split NewWindow
let input = input('>> ')
和
botright split NewWindow
redraw!
let input = input('>> ')
第一个总是在打开新 window 之前让我输入。在它们两个中, >>
部分都没有出现(输入本身也没有)。他们怎么做到的?一堆 getchar
个电话?
(使用 Neovim v0.2.0)
好的。似乎并没有那么困难(由于某种原因我迷失在源代码中而看不到它)。他们基本上一次得到一个字符并不断回显结果。
据我所知,CtrlP 使用了以下方法:
- 重画
- 用
getchar()
求字符
- 将字符与累加器字符串连接起来
- 回显字符串
- 想循环就循环
我的 vimscript 现在看起来像这样:
let str = ''
while s:some_stop_condition()
redraw
let c = getchar()
let str = str . nr2char(c)
echo str
endwhile