Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Stata with MacVim

From   Gabi Huiber <[email protected]>
To   [email protected]
Subject   Re: st: Stata with MacVim
Date   Thu, 4 Aug 2011 17:20:55 -0400

Thanks, Phil, for your help. I am making some progress, but I'm not there yet.

I will just take one problem at a time: first I sort out how to make
Stata do a do-file from within MacVim. Making it do a selection of
lines can wait.

The do-file bash script you suggested kind of works. Suppose I had a
do-file in the Documents folder that had two lines in it:

__________do-file starts here__
di "Hello World!"
di "Hello Gabi."
_____________and ends here__

Now suppose that, in terminal, I type

$ do-file Documents/

This makes Stata 12 start up with the do-file editor open with a blank
do-file that is called In the terminal window, meanwhile, I
get the warning "missing value".

The same thing happens if I edit Documents/ in Vim and in
command mode I type :!do-file %.

This only happens once. Subsequent calls to do-file, after Stata is
running, either in terminal or in the Vim command mode, produce the
"missing value" warning but have no effect on Stata, as far as I can

If, instead, at the terminal I type

$ do-file ~/Documents/

Then Stata will start with the do-file editor open with the correct
do-file loaded. The warning message in this case is

<<class >>

The blank spaces on either side of >> are as shown above, if that
matters. Again, this only happens once.

I have tried other tricks too, with help from the MacVim e-mail list.
For example, one way to get Stata to open my do-file in the editor
without any warning messages is to rewrite my RunIt() function as

function RunIt()
  !rm -Rf ~/Library/Saved*/com.stata*
  !osascript -e 'tell app "StataMP" to open "%:p"'

:map <F7> :<C-U>call RunIt()<CR><CR>
:imap <F7> <Esc>:<C-U>call RunIt()<CR><CR>

The first shell command there, "rm -Rf [...]", obliterates the Stata
MP state that Lion saves by default when you quit Stata, so it
basically forces Stata to start with a clean slate. Details are here:

Still, the original problem remains not solved: I don't want Stata to
help me edit this do-file. I want it to do it for me, as many times as

Thanks again,


On Mon, Aug 1, 2011 at 7:33 PM, Phil Schumm <[email protected]> wrote:
> On Jul 31, 2011, at 12:14 PM, Gabi Huiber wrote:
>> Has anybody managed to integrate Stata with MacVim? I have made an attempt but I am stuck, as follows:
>> There is an old Statalist post by Dimitriy Masterov about getting Stata to launch from Vim on Windows, here:
> You'll need to communicate with Stata via Apple events, which is most easily done via Applescript.  For example, to send the file you are currently editing to Stata, you could create the following (executable) shell script (note that you'll need to modify the Bundle identifier if you're using Stata 12):
> ----------------------- do-file -----------------------
> #!/bin/bash
> osascript -e "tell application id \"com.stata.stata11\"
>        open POSIX file \"${1}\"
> end tell"
> -------------------------------------------------------
> Place the script on your path, and then, while editing a do-file in vim, do
>    :! do-file %
> Similarly, if you wish to send a visual selection to Stata, create a script like the following:
> --------------------------------- do-selection --------------------------------
> #!/bin/bash
> TMPFILE=".stata-$$.do"
> if [ ! -e "$TMPFILE" ]
> then
>    cat > "$TMPFILE"
>    osascript <<-APPLESCRIPT
>        tell application id "com.stata.stata11" to open POSIX file "${TMPFILE}"
>        delay 0.5  -- avoid deleting file before Stata reads it
>        do shell script "rm \"${TMPFILE}\""
> else
>        echo "Can't create temporary file $TMPFILE (already exists)"
> fi
> -------------------------------------------------------------------------------
> Select the lines in vim you want to execute, and do
>    :'<,'>w !do-selection
> I'm afraid I don't have time right now to test this code, or to give additional details.  Moreover, I'm a novice vim user (I use it for remote system administration only), so I can only help you on the Applescript part.  If you run into trouble, let me know.
> -- Phil
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index