命令行中的vi输入模式Matlab?

我在~/.inputrc有这些行:

 set editing-mode vi set keymap vi 

这允许我在每个使用GNU读取行进行文本输入的程序中使用vi键绑定。 示例: pythonirbsftpbashsqlite3等。 它使得使用命令行变得轻而易举。 Matlab 使用readlines,但是在调试或交互式工作时, vi keybinding会很棒 。 有现成的解决方案吗?

我倾向于matlab -nosplash -nodesktop使用matlab -nosplash -nodesktop ,这让我思考:是否可以编写一个使用readlines并将输入传递给matlab的包装器? (如果我必须实现这个,我可能更喜欢在Ruby中这样做。)

更新:

谢谢您的帮助。 这几乎有效:

 # See also: http://bogojoker.com/readline/ require 'readline' puts 'Starting Matlab...' io = IO.popen('matlab -nosplash -nodesktop 2>&1', 'w+') while input_line = Readline.readline('>> ', true) io.puts input_line puts io.gets end 

但它一次只从Matlab读取一行(因为我正在使用gets )。 关于如何在下次等待输入之前获取所有内容的任何想法? 这是正在发生的事情(我在>>提示符下输入内容):

 Starting Matlab... >> 1 >> 2  >> 3 Copyright 1984-2009 The MathWorks, Inc. >> 4 Version 7.8.0.347 (R2009a) 32-bit (glnx86) >> 5 February 12, 2009 >> 6 >> 7 >> 8 To get started, type one of these: helpwin, helpdesk, or demo. >> 9 For product information, visit www.mathworks.com. >> 0 >> 1 >> >> 2 ans = >> 3 >> 4 1 >> 5 >> 6 >> >> 7 ans = >> 8 >> 9 2 >> 0 >> 1 >> >> 2 ans = >> 3 >> 4 3 

是的,这应该很容易。 这只是一般情况下“打开一个进程并绑定其stdin和stdout”问题的一个特例,这并不困难。

一些谷歌搜索发现IO.popen()是Ruby的正确部分,这里的回复还有一些细节: http : //groups.google.com/group/ruby-talk-google/ browse_thread / thread / 0bbf0a3f1668184c 。 希望,这足以让你开始!

更新:看起来你的包装几乎就在那里。 你需要完成的是识别Matlab何时要求输入,然后只询问用户输入。 我建议尝试这个伪代码:

 while input_line = Readline.readline('>> ', true) io.puts input_line while ((output_line = io.gets) != '>> ') // Loop until we get a prompt. puts io.gets end end 

这不太对,因为在你要求第一个输入行之前你需要做一次内循环,但它应该给你一个想法。 您可能还需要调整它正在查找的提示文本。

更新2:好的,所以我们还需要考虑提示后没有EOL的事实,因此io.gets将挂起。 这是一个修订版本,它使用了一个事实,你可以给Matlab提示一个空行,它只会给你另一个提示而不做任何事情。 我已经重新安排了循环以使事情变得更清晰,但这意味着你现在必须添加逻辑来弄清楚你什么时候完成。

 while [not done] // figure this out somehow io.puts blank_line // This will answer the first // prompt we get. while ((output_line = io.gets) != '>> ') // Loop until we get a prompt. puts io.gets // This won't hang, since the end // prompt will get the blank // line we just sent. input_line = Readline.readline('>> ', true) // Get something, feed it io.puts input_line // to the next prompt. output_line = io.gets // This will eat the prompt that corresponds to // the line we just fed in. end 

你可以直接使用rlwrap

 rlwrap is a wrapper that uses the GNU readline library to allow the editing of keyboard input for any other command. 

http://utopia.knoware.nl/~hlub/rlwrap/#rlwrap

不幸的是,它将在MATLAB中阻止上下文相关的选项卡完成,这本身很有用。

实际上,你可能最好用C语言编写 – 然后你可以直接调用matlab引擎 。 这基本上允许您使用GNU Readline库将自己的前端编写到matlab,如果您愿意的话。