Last Updated: February 25, 2016
·
592
· cpatuzzo

Vim - Background Server

If your Vim has +ruby support, you can syntax highlight the current file and serve it over rack relatively simply.

Create a file with the following contents, then run :ruby load "filename.rb" inside Vim.

You can then visit localhost:1234 in your browser.

require "rack"
require "rack/source"

app = Rack::Source.new(__FILE__, lexer: :ruby)

child = fork do
  Rack::Handler::WEBrick.run(
    app,
    AccessLog: [],
    Logger: WEBrick::Log::new("/dev/null", 7),
    Port: 1234
  )
end

Process.detach(child)