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" <>
To   Statalist <>
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

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()
 !start "C:\Program Files\Scripts\rundo.exe" "%:p"

: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("'>"))
if col("'<") != 1
  let selectedLines[0] = strpart(selectedLines[0], col("'<")-1)

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

:map <F9> :<C-U>call RunDoLines() <Enter>
:imap <F9> <Esc>:<C-U>call RunDoLines() <Enter>
*   For searches and help try:

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