Skip to content

07CalC/cook.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍳 cook.nvim

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.

default runner based on file extension

default-cook-demo

custom project recipes

recipes-cook-demo

:Coop auto paste the clipboard, helpful for Competetive Programming

coop-cook-demo

Supports:

  • 🐍 Python
  • πŸ¦€ Rust
  • 🧠 C/C++
  • πŸŒ€ JavaScript / TypeScript
  • 🦫 Go

✨ Features

  • πŸ“‚ 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 like cmake-tools.nvim
  • πŸ’‘ Minimal setup, pure Lua

πŸš€ Installation

Using lazy.nvim:

{
  "07CalC/cook.nvim",
  config = function()
    require("cook").setup()
  end,
  cmd = "Cook",
}

Using packer.nvim:

use {
  "07CalC/cook.nvim",
  config = function()
    require("cook").setup()
  end
}

πŸ”§ Usage

:help cook

Default

In any buffer, simply run:

:Cook

It will:

  1. Detect the filetype by extension.
  2. Build the appropriate shell command.
  3. Open a floating terminal and run it.

Custom recipes

If your project has a recipes.lua in its root, you can:

:Cook dev
:Cook build

πŸ“¦ Project Recipes (recipes.lua)

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 using vim.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.

🧠 CP Mode with :Coop

Competitive programming guys, this is for you. Just copy the input (from a problem description) to clipboard, then run:

:Coop

It will:

  1. Detect your filetype.
  2. Create a temp file with clipboard contents.
  3. Pipe the input to your program (< input.in).
  4. Show the output in a terminal buffer.

No need to manually paste or prepare files!

πŸ› οΈ Supported Languages & Commands

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",
  },
})

πŸͺŸ Terminal Layout Options

By default, cook.nvim opens a floating terminal, but you can change this behavior to suit your workflow.

Available Layouts:

  • float β†’ centered floating terminal (default)
  • bottom β†’ splits and runs in bottom window
  • vertical β†’ opens terminal in a vertical split

πŸ”§ Configuration Example

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
  },
})

πŸ“ File Structure

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

πŸ™Œ Contributing

PRs are welcome! You can:

  • Add support for more languages
  • Improve command detection
  • Add UI options (like vertical split)

About

nvim code runner plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages