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   Phil Schumm <>
Subject   Re: st: Stata with MacVim
Date   Mon, 1 Aug 2011 18:33:19 -0500

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 -----------------------
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 --------------------------------
if [ ! -e "$TMPFILE" ]
    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}\""
	echo "Can't create temporary file $TMPFILE (already exists)"

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:

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