A Neovim plugin with keymaps for working with Snakemake workflows: quickly add --forcerun arguments to your run.sh, and jump from any input file to the rule that produces it.
Place your cursor anywhere inside a Snakemake rule definition, press the keymap, and the plugin will:
- Scan upward from the cursor to find the enclosing
rule my_rule:line and extract the rule name - Open
run.shin Neovim's current working directory - Insert or update the
--forcerunargument in the file - Save the file
First use: a --forcerun rule_name \ line is inserted directly after the snakemake command.
Subsequent uses: if a --forcerun line is already present, the new rule name is appended to it (space-separated) — so you can build up a list of rules to force-rerun without editing run.sh by hand.
Place your cursor on a quoted input filename inside any rule's input: block and press the keymap. The plugin will:
- Extract the file string under the cursor
- Scan all
Snakemake*andSnakefile*files under the current working directory, collecting every rule and checkpoint'soutput:patterns - Match the filename against each output pattern — including wildcard patterns like
results/{sample}.bam - Open the file containing the matching rule (if different from the current buffer) and jump to it
Both exact matches (pattern equals pattern) and concrete-to-wildcard matches are supported. For example, with cursor on "results/sampleA.bam" in an input block, the plugin will jump to a rule with output: "results/{sample}.bam". The rule name and source file are shown in a notification.
Note: Only static quoted strings in
output:blocks are indexed.expand()results, lambdas, and function callbacks are not evaluated.
- Neovim
- A
run.shfile in Neovim's current working directory containing asnakemakecommand
{
"samesense/snakemake.nvim",
config = function()
require("snakemake").setup()
-- add current rule to --forcerun in run.sh
vim.keymap.set("n", "<Leader>o", function()
require("snakemake").open_and_insert()
end)
-- jump to the rule that produces the file under cursor
vim.keymap.set("n", "<Leader>g", function()
require("snakemake").goto_producer()
end)
end,
},- Open a Snakefile in Neovim
- Place your cursor anywhere inside a rule — on the
ruleline itself or any line within the rule body:rule my_rule: input: "data.txt" # cursor can be here too output: "result.txt" - Press
<Leader>o - Your
run.shwill be updated — the rule is inserted after thesnakemakeline on the first use, or appended to the existing--forcerunline on subsequent uses
For example, after pressing <Leader>o three times on different rules:
snakemake \
--forcerun rule_a rule_b rule_c \
--cores 4Note: An error is raised if no
ruledefinition is found above the cursor, or ifrun.shdoes not contain asnakemakeline and no--forcerunlines are present.
- Open a Snakefile in Neovim
- Place your cursor on a quoted filename inside an
input:block:rule final: input: "results/sampleA.bam" # cursor here - Press
<Leader>g - The cursor jumps to the rule whose
output:produces that file
Wildcard patterns are matched automatically — a concrete filename like results/sampleA.bam will match an output pattern results/{sample}.bam. The rule name is shown in a notification on successful navigation.