A Neovim plugin that provides seamless integration with Stata, allowing you to send code from Neovim to a running Stata instance. Inspired by stata-exec for Atom/Pulsar.
- Send current dofile, selected line or paragraph to Stata
- Automatically advance the cursor after sending code
- Supports
line /// continuations
) and/* Block comments */
- Curently for Linux - Xorg. Experimental implementation on Mac OS
- Stata: StataSE, StataMP, or StataIC installed
xclip
for clipboard managementxdotool
for window management and keyboard control
Install them with:
# Debian/Ubuntu
sudo apt-get install xclip xdotool
# Fedora
sudo dnf install xclip xdotool
# Arch Linux
sudo pacman -S xclip xdotool
Using lazy.nvim
Add the following to your Neovim configuration:
{
"vedshastry/xstata-nvim",
config = function()
require('xstata-nvim').setup({
-- Configuration options (defaults shown)
which_app = "StataMP", -- Options: StataMP, StataSE, StataIC, Stata
advance_position = true, -- Move cursor to next line after sending current line
skip_comments = true, -- Skip comment lines when advancing position
focus_window = true, -- After code is sent, bring focus to Stata
})
end,
ft = { "stata", "do", "ado", "mata" }, -- Load only for Stata file types
}
- Clone the repository into your Neovim packages directory:
git clone https://github.com/vedshastry/xstata-nvim.git ~/.local/share/nvim/site/pack/plugins/start/xstata-nvim
- Add the following to your init.lua:
require('xstata-nvim').setup({
-- Your configuration options here
})
The plugin provides the following commands:
:StataRun
- Send the current line or visual selection to Stata:StataRunAll
- Run the entire current buffer as a do-file:StataRunParagraph
- Run the current paragraph (text block):StataRunPrevious
- Re-run the previous command
<Leader>rr
: Run (current line or visual selection)<Leader>ra
: Run all (entire buffer as a dofile)<Leader>rp
: Run paragraph (until first empty line after current)<Leader>rc
: Run previous command
You can set up your own keybindings by adding them to your Neovim configuration:
-- Run current line or selection (when in visiual mode) with Ctrl+Enter
vim.keymap.set('n', '<C-CR>', ':StataRun<CR>', {noremap = true, silent = true})
vim.keymap.set('v', '<C-CR>', ':StataRun<CR>', {noremap = true, silent = true})
-- Run entire buffer with Ctrl+Shift+D
vim.keymap.set('n', '<C-S-d>', ':StataRunAll<CR>', {noremap = true, silent = true})
-- Run paragraph with Ctrl+Alt+Enter
vim.keymap.set('n', '<C-A-CR>', ':StataRunParagraph<CR>', {noremap = true, silent = true})
You can customize the plugin behavior with these options:
require('xstata-nvim').setup({
-- Stata application to use (macOS)
which_app = "StataMP", -- Options: StataMP, StataSE, StataIC, Stata
-- Automatically move cursor to next line after sending code
advance_position = false,
-- Skip comment lines when advancing cursor
skip_comments = true,
-- After sending code, focus Stata window
focus_window = true,
})
- If
xdotool
can't find the Stata window, try running the following command in the terminal to see if Stata is properly detected:If this command doesn't return a window ID, you may need to adjust the search pattern in thexdotool search --name --limit 1 "Stata/"
sender.lua
file.
- Make sure the application name in
which_app
matches exactly with the name of your Stata application. - If code is not being sent to Stata, check that you have the necessary permissions for AppleScript to control Stata.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License