Page:
Recipes
Pages
Architecture and Philosophy
Configuration Guide
Contributor Validation Matrix
Drawing and Visuals
Example Configs Overview
Example Shared Helpers
Example TTY Baseline
Example Tiling
Feature Status and Limitations
Feature and Support Matrix
Getting Started
Home
Hook Payload Summary
Hooks Guide
IPC Protocol
Lua API Cheat Sheet
Lua API Guide
Lua Basics for evil
Queries Commands and Actions
Recipes
Testing and Debugging
Writing Your First Config
No results
5
Recipes
Agent edited this page 2026-05-26 05:18:08 -04:00
Recipes
This page collects small practical patterns you can copy into your own config.
Focus every new window
evil.on.window_mapped = function(ctx)
evil.window.focus(ctx.window.id)
end
Click to focus
evil.on.resolve_focus = function(ctx)
if ctx.reason == "pointer_button" and ctx.window then
evil.window.focus(ctx.window.id)
return
end
if ctx.reason == "pointer_button" and not ctx.window then
evil.window.clear_focus()
end
end
Move windows freely
evil.on.move_update = function(ctx)
evil.window.move(ctx.window.id, ctx.window.x + ctx.dx, ctx.window.y + ctx.dy)
end
Resize windows freely
evil.on.resize_update = function(ctx)
evil.window.resize(ctx.window.id, ctx.window.w + ctx.dx, ctx.window.h + ctx.dy)
end
Snap movement to a grid
local GRID = 64
local function snap(value)
return math.floor((value / GRID) + 0.5) * GRID
end
evil.on.move_update = function(ctx)
evil.window.move(ctx.window.id, snap(ctx.window.x + ctx.dx), snap(ctx.window.y + ctx.dy))
end
Put new windows near the focused window
evil.on.place_window = function(ctx)
for _, window in ipairs(ctx.state.windows) do
if window.focused then
evil.window.move(ctx.window.id, window.x + window.w + 24, window.y)
return
end
end
end
Launch a terminal from a key hook
evil.on.key = function(ctx)
if ctx.keyspec == "Super+Return" then
evil.spawn("foot")
end
end
Keep a focused border
evil.on.draw_window_overlay = function(ctx)
local focused = ctx.focused_window
if not focused then
return {}
end
return {
evil.draw.stroke_rect({
space = "world",
x = focused.x,
y = focused.y,
w = focused.w,
h = focused.h,
width = 2,
outer = 2,
color = { 0.8, 0.6, 1.0, 1.0 },
}),
}
end
Disable free canvas navigation in a profile
evil.config({
canvas = {
min_zoom = 1.0,
max_zoom = 1.0,
zoom_step = 1.0,
pan_step = 0,
allow_pointer_zoom = false,
allow_middle_click_pan = false,
allow_gesture_navigation = false,
},
})
Read next
evil wiki
- Home
- Getting started
- Architecture and philosophy
- Configuration guide
- Writing your first config
- Lua basics for evil users
- Lua API guide
- Lua API cheat sheet
- Hooks guide
- Hook payload summary
- Queries, commands, and actions
- Drawing and visuals
- Example configs overview
- Example shared helpers and rules
- IPC protocol
- Testing and debugging
- Contributor validation matrix
- Feature status and limitations
- Feature and support matrix
- Recipes