代码之家  ›  专栏  ›  技术社区  ›  Biswanath

在scala sbt控制台中使用vim,scala repl?

  •  2
  • Biswanath  · 技术社区  · 7 年前

    有没有办法像在bash上那样,使用VIM在sbt控制台(scala repl)上编辑和输入当前命令。bash提供了从vim编辑当前命令的选项。

    2 回复  |  直到 7 年前
        1
  •  2
  •   Eugene Yokota    7 年前

    不,没有使用Vim编辑当前命令的内置支持。

    sbt 1.x和Scala 2.12.x都使用JLine2进行行编辑(使用上箭头和制表符完成历史记录)。虽然JLine2有基本的vi命令模拟,但它似乎不支持将当前行发送到 VISUAL 编辑。

    vi命令仿真

    要启用vi移动,请在 $HOME/.inputrc :

    set editing-mode vi
    

    启动Scala REPL时,键入 ESC Ctrl + [ . 现在你可以:

    • k 回到以前的历史。
    • ?something 在历史缓冲区中搜索“某物”, n 再次搜索。
    • w 转到下一个单词, b 移到上一个单词。
    • i 返回到插入模式。
        2
  •  0
  •   Chris B    7 年前

    如果有帮助的话,这里有一些vim脚本,我有时用来运行Scala REPL中当前vim缓冲区的内容:

    " Write the current buffer to a temp file and load it in the Scala REPL
    function RunInScalaREPL()
        let l:tmpfile = tempname() . '.scala'
        execute 'write ' . l:tmpfile
        execute '!scala -i ' . l:tmpfile
    endfunction
    command Scala call RunInScalaREPL()
    command REPL call RunInScalaREPL()