While I was working for a MOOC the other day, I realized that the professor was using a combination of Emacs and something called SML Mode to start the SML interpreter right inside the editor. Jealousy hit me—being myself a Vim evangelist—and I immediately started my search for something similar in the VI world.
My solution is a neat two-liner, ready to be copied into your Vim config file, e.g.
autocmd FileType sml command Sml !sml '%' map #5 :Sml^M
Okay, what’s happening here? First, we create a new command called
Sml (please note that user-defined commands have to be capitalized) which is available whenever we work with SML files. Now, when you type :Sml in Vim you will switch to the shell and find yourself in the SML interpreter.
Better yet, the percent sign is replaced by the current file name. That means your code will be loaded into SML automatically and is ready to be used (or will throw an exception, in case you screwed up). Isn’t that lovely? If that is what you want, we are done and it needed only one line of Vim configuration. But there’s more!
In Vim you can assign a frequently used command sequence to a key to save you some keystrokes and time. That’s what’s happening in line two: We map
:Sml^M to the F5 function key. Please be careful with the last character on that line, since it is not a caret and an M, but rather one single character signifying an Enter keystroke. To get this escaped control key hit Ctrl-V and Enter.
That’s all it takes to have the SML interpreter at your fingertip while coding.