cook.nvim is a modular and extensible Neovim plugin that lets you effortlessly compile or run the current file based on its filetype β inside a floating terminal.
Supports:
- π Python
- π¦ Rust
- π§ C/C++
- π JavaScript / TypeScript
- 𦫠Go
- π Runs code from the current buffer based on its extension
- πͺ Opens a floating terminal inside Neovim
- βοΈ Easily extendable for any language
- π¦ Define per-project tasks with
recipes.lua
- π§ Smart filetype-to-runner resolution
- π
:Coop
mode for Competitive Programming - β Tasks starting with
!
run as native Vim commands β useful for plugins likecmake-tools.nvim
- π‘ Minimal setup, pure Lua
{
"07CalC/cook.nvim",
config = function()
require("cook").setup()
end,
cmd = "Cook",
}
use {
"07CalC/cook.nvim",
config = function()
require("cook").setup()
end
}
:help cook
In any buffer, simply run:
:Cook
It will:
- Detect the filetype by extension.
- Build the appropriate shell command.
- Open a floating terminal and run it.
If your project has a recipes.lua
in its root, you can:
:Cook dev
:Cook build
Define custom tasks at the project root (detected via .git or recipes.lua) using a recipes.lua file:
--- recipes.lua
return {
recipes = {
dev = "cargo watch -x run"
build = "cargo build --release"
test = "cargo test"
fmt = "cargo fmt"
cmake_build = "!CMakeBuild" -- runs as a Vim command
}
}
π Note:
- Commands starting with
!
are executed usingvim.cmd()
, letting you run Vim-native or plugin-provided commands. - Use keymap
<ESC><ESC>
to leave terminal mode. - Use command
:Cookt
or keymap<leader><leader>t
to toggle terminal.
Competitive programming guys, this is for you. Just copy the input (from a problem description) to clipboard, then run:
:Coop
It will:
- Detect your filetype.
- Create a temp file with clipboard contents.
- Pipe the input to your program (< input.in).
- Show the output in a terminal buffer.
You can configure your own runners, but here are the defaults:
runners = {
py = "python3 %s",
c = "gcc %s -o %s && %s",
cpp = "g++ %s -o %s && %s",
rs = "cargo run",
js = "bun %s",
ts = "bun %s",
go = "go run %s",
}
You can customize this via:
require("cook").setup({
runners = {
py = "python %s",
sh = "bash %s",
},
})
By default, cook.nvim
opens a floating terminal, but you can change this behavior to suit your workflow.
float
β centered floating terminal (default)bottom
β splits and runs in bottom windowvertical
β opens terminal in a vertical split
require("cook").setup({
terminal = {
layout = "float", -- or "bottom", "vertical"
width = 0.8, -- used for floating and vertical layout
height = 0.3, -- used for floating and bottom layout
border = "rounded", -- border style for floating terminal
},
})
lua/
βββ cook/
βββ init.lua -- Entry point
βββ config.lua -- Plugin config and default runners
βββ filetype.lua -- Filetype-based runner resolution
βββ executor.lua -- Terminal execution
βββ commands.lua -- Maps user commands (Cook, Coop)
βββ recipes.lua -- Project-local task loader
PRs are welcome! You can:
- Add support for more languages
- Improve command detection
- Add UI options (like vertical split)