Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: AutoIt and Vim Scripts


From   "Dimitriy V. Masterov" <dvmaster@gmail.com>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   st: AutoIt and Vim Scripts
Date   Tue, 27 Jun 2006 22:52:30 -0400

I made some modifications to the script that runs do-files from Vim. I
thought they may be of interest to some of you. Putting this in your
_gvimrc file will map F8 to run the whole file and F9 to run the
selected part of the do-file using only F. Huebler's Script 1, which
you can download from

http://mysite.verizon.net/huebler/2005/20050310_Stata_editor.html#script1

You may need Vim 7.0 to take advantage of the F9 mapping. This fixes
the bug which left an "extra" copy of the do-file after using F8, and
it also allows you to run only a part of the file (regardless of if
the text s selected in visual mode or the mouse way). As always, you
may need to change the paths to suit your PC.

Here's the code:

" Define Scripts and Map Them
fun! RunIt()
 wa
 !start "C:\Program Files\Scripts\rundo.exe" "%:p"
endfun

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


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

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

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

 exec "!start C:\\Program Files\\Scripts\\rundo.exe " . temp

" Delete the temp file after Vim closes
 au VimLeave * exe "!del -y" temp
endfun

:map <F9> :<C-U>call RunDoLines() <Enter>
:imap <F9> <Esc>:<C-U>call RunDoLines() <Enter>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index