Configuring Sublime Text 2 To Work With FSharp

I like working with the Sublime Text 2 editor and I surely like to work with FSharp so I’ve been trying to find ways to make life easier for myself.  A few tips to pass along:

  1. Get the F# Textmate Bundle. Once you get it, unzip it into the ~\Application Data\Sublime Text 2\Packages directory.  In my case I created a F# directory under the Packages directory.
  2. Add the following settings via the File Settings-User menu
    	"tab_size": 4,
    	"translate_tabs_to_spaces": true
    
  3. To make it easier to compile and build your app, create a couple of environment variables: MSBuildBin and FSBin. In my case I set the MSBuildBin to the directory where the MSBuild.exe is located and I set FSBin to the directory where Fsc.exe is located.

Under the ~\Application Data\Sublime Text 2\Packages\User directory, create a file called msbuild.sublime-build and put the following in it:

{
    "path": "%FSBin%;%MSBuildBin%",
    "cmd": ["msbuild"]
}

Once you do this, on the Tools->Build System menu, you should have an msbuild option.  If you select the msbuild option from the build system you should be able to build your FSharp app with an msbuild *.proj file.  You can grab the lines from the output via a Perl RegEx if you want but I’ve not done anything so complex up to this point.

I’m working on adding the ability to shell out to the fsi.exe utility.  If I make any progress with that, I’ll post on it here.

UPDATE: See Leaf’s comment below for information on adding a REPL to Sublime Text 2. Great many thanks Leaf.

Also, here is a Gist of a small, modest F# shell script to kick off Sublime Text 2 adding git into the path for the ST2 git plug-in.

UPDATE 2:  The eminent F# developer, PaulMichael Blasucci has created a new Sublime Text 2 plug-in for F# developers.

Technorati Tags: ,,

10 responses

  1. For fsi.exe shell, you can easily configure SublimeREPL (https://github.com/wuub/SublimeREPL) to use it. I have something like this setup:

    {“command”: “repl_open”,
    “caption”: “F#”,
    “mnemonic”: “f”,
    “args”: {
    “type”: “subprocess”,
    “encoding”: “utf8”,
    “cmd”: [“C:/Program Files (x86)/Microsoft F#/v4.0/Fsi.exe”, “–utf8output”, “–gui-“],
    “cwd”: “$file_path”,
    “syntax”: “Packages/FSharp/F#.tmLanguage”
    }
    }

    • Hmm..ST 2 can’t find the fsi.exe when I start SublimeRepl. I’ve added the above conf to both user and default settings for SublimeRepl (not sure where to add it). Any ideas? Thanks.

      • Try running the string you have in your cmd parameter from a command prompt and see what happens. Basically if you can find the command to start fsi from your command prompt, that’s what you’ll want to put in the “cmd” parameter.

      • It doesn’t seem to read the conf at all; when I added the path to fsi.exe in the system environment variable it was found but then it complained about F#.tmLanguage which it looked for in Packages/F# but I specified the path to be Packages/FSharp/FSharp.tmbundle/Syntaxes. Oh well, a good night’s sleep might do the trick. Thanks for a great blog!

  2. Pingback: Configuring Sublime Text 2 To Work With FSharp « Random misspellings

  3. Pingback: F# for Functional Enthusiasts Bibliography | craftyThoughts

  4. Pingback: Fisherman’s Catch of 2014-02-08 | Data's Fisherman

  5. Pingback: Fisherman’s Catch of 2014-02-08 | evalpoint

Leave a comment