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]

st: Stata with MacVim

From   Gabi Huiber <>
To   The Statalist <>
Subject   st: Stata with MacVim
Date   Sun, 31 Jul 2011 12:14:21 -0500

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:
Dimitriy's script makes use of rundo.exe, written by Friedrich Huebler
and described at

I know this works because I used it for Stata 10+Vim 7.3+Win 7 Pro.
Now I am trying to accomplish the same thing with Stata 12+MacVim+Mac
OS X Lion.

My Vim script is below:


function RunIt()
  !open -a StataMP --args do "%:p"

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

function RunDoLines()
  let selectedLines = getbufline('%', line("'<"), line("'>"))

 if col("'>") < strlen(getline(line("'>")))
   let selectedLines[-1] = strpart(selectedLines[-1], 0, col("'>"))
 if col("'<") != 1
   let selectedLines[0] = strpart(selectedLines[0], col("'<")-1)

 let temp = tempname() . ".do"
   call writefile(selectedLines, temp)

   exec "!open -a StataMP --args do " . temp

   " Delete the temp file after Vim closes
   au VimLeave * silent exe '!rm "'.$TEMP.'\*.do"'

:map <F8> :<C-U>call RunDoLines()
:imap <F8> <Esc>:<C-U>call RunDoLines()

The trouble is, my script doesn't work as well. It can call either
RunDo() or RunDoLines() and it will correctly launch Stata with a do
command that applies either to the whole do-file being edited, or to
the selected lines, as expected. But it will do either action only
once. Subsequent calls to either RunDo() or RunDoLines() will be
ignored until Stata is restarted.

I would appreciate any ideas about how I could fix this.

Thank you,
*   For searches and help try:

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