VIM:当光标移动时在每一行执行 Ruby 脚本并更新缓冲区以在拆分窗口中显示
我正在尝试用 VIM 解决问题。这就是我想要实现的目标:
我有一个包含几行的文件。当我将光标从一行移动到另一行时,我想将当前行作为参数发送给 Ruby 脚本。该脚本的结果应重定向到 VIM 缓冲区,该缓冲区将显示在原始文本上方的拆分窗口中。
到目前为止,我已经能够编写一个函数,将一行发送到脚本,结果显示在上面的缓冲区中。我不确定如何让这个函数在每次光标移动到新行时运行并使结果更新相同的缓冲区。任何指示将不胜感激。
我的代码:
function! BB()
redir => a
let str = getline(".")
let str1 = "\"" . str . "\""
silent execute "!${HOME}/scripts/test.rb " . str1
redir END
new
put! = a
endfunction
command! -nargs=0 BB echo BB()
I'm trying to solve a problem with VIM. Here is what I'm trying to achieve:
I have a file with several lines in it. As I move my cursor from line to line, I want to send the current line as an argument to a Ruby script. The result of this script should be redirected to a VIM buffer which will be shown in a split window above the original text.
so far, I have been able to write a function that sends one line to the script and the results show up in a buffer above. I am not sure how to get this function to run each time the cursor moves to a new line and make the results update the same buffer. Any pointers would be appreciated.
My code:
function! BB()
redir => a
let str = getline(".")
let str1 = "\"" . str . "\""
silent execute "!${HOME}/scripts/test.rb " . str1
redir END
new
put! = a
endfunction
command! -nargs=0 BB echo BB()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先想到的是映射按键动作。像这样的东西:
The first thing that comes to my mind is mapping keys movements. Something like: