I've never wanted to do anything like that, but do you need the vi editing to actually happen within your application? If not, you could do like most text-mode email clients and create a temporary file, fire up an editor session to edit that file, read the temp file back in when the editor closes, and then delete the temp file when you're done with it. This also has the advantage of being easy to set up such that the user can (via config file or environment setting) specify the editor of their choice instead of being hardwired to vi.