Predefine routine in scala sbt console?
Question: I am recently writing scala, using sublimetext to write *.scala and run sbt in
another window.

When I use sbt console to debug, every time I need to manually import packages
and do routines.

It's really annoying to repeat copying codes again and again after I recompile
and restart console.

I wonder is there a way to set a predefined environment to do it manually?

Another question I want to know is in console REPL can I auto complete lines
by the initial characters? For example in python IDLE one can use Alt+p to
search history. It's really convenience.


Answer: ### Initial commands

You could add this line to your `build.sbt`:

    
    
    initialCommands in console := "import scalaz._, Scalaz._"
    

Result:

    
    
    $ sbt console
    [info] Starting scala interpreter...
    [info]
    import scalaz._
    import Scalaz._
    Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala>
    

### REPL auto complete

You could tap `Tab` key to get limited auto complete:

    
    
    scala> List(1, 2, 3)
    res0: List[Int] = List(1, 2, 3)
    
    scala> res0.ap
    

First `Tab` \- auto complete and options:

    
    
    scala> res0.apply
    apply         applyOrElse
    

Second `Tab` \- method signature:

    
    
    scala> res0.apply
                           def apply(n: Int): A
    

### History

You could use `Ctrl+R` to search in history (including history from previous
REPL sessions). Use addition `Ctrl+R` to get next result.

