GPUI Actions and Keyboard Shortcuts

VerifiedSafe

Define actions and keyboard shortcuts in GPUI with context-aware key bindings. Practical Rust guide.

Sby Skills Guide Bot
DevelopmentIntermediate
11/2/2026
Claude CodeCursor
#rust#gpui#keyboard-shortcuts#ui#actions

Recommended for

Automated summary

Explains how to declare actions and bind keyboard shortcuts in GPUI, the Rust UI framework, with examples for simple actions, parameterized actions, and key contexts.

Strengths

  • Complete, copy-ready quick-start snippets (actions! macro, bind_keys, on_action)
  • Covers parameterized actions via #[derive(Action)] with namespace and no_json
  • Includes a reference table of key formats and modifiers
  • Emphasizes key contexts and verb-noun action naming conventions

Limitations

  • Does not detail focus-based routing or action dispatch, deferring to reference.md
  • Assumes GPUI familiarity and a specific API version, with no compatibility notes
  • Says nothing about testing or error handling inside action handlers
When to use it

Use it when adding keyboard-driven commands or key bindings to a Rust application built with GPUI.

When not to use it

Avoid it for other Rust UI frameworks (egui, iced, Tauri) or when you need an introduction to GPUI's overall architecture.

Security analysis

Safe
Quality score86/100

This is a documentation-only skill explaining GPUI action definitions and keybindings in Rust. It contains no executable instructions, network calls, secrets handling, destructive commands, or attempts to alter the auditor's behavior.

No concerns found

How this analysis is made

Examples

Add save/quit shortcuts
In my GPUI editor app, add Save and Quit actions bound to cmd-s and cmd-q, scoped to an "Editor" key context.
Parameterized digit actions
Create a GPUI action that carries a u8 digit payload and bind the number keys 0-9 to it using #[derive(Action)].
Context-aware Escape key
My GPUI app has a modal and an editor; make Escape close the modal when it is open and clear the editor selection otherwise.

name: gpui-action description: Action definitions and keyboard shortcuts in GPUI. Use when implementing actions, keyboard shortcuts, or key bindings.

Overview

Actions provide declarative keyboard-driven UI interactions in GPUI.

Key Concepts:

  • Define actions with actions! macro or #[derive(Action)]
  • Bind keys with cx.bind_keys()
  • Handle with .on_action() on elements
  • Context-aware via key_context()

Quick Start

Simple Actions

use gpui::actions;

actions!(editor, [MoveUp, MoveDown, Save, Quit]);

const CONTEXT: &str = "Editor";

pub fn init(cx: &mut App) {
    cx.bind_keys([
        KeyBinding::new("up", MoveUp, Some(CONTEXT)),
        KeyBinding::new("down", MoveDown, Some(CONTEXT)),
        KeyBinding::new("cmd-s", Save, Some(CONTEXT)),
        KeyBinding::new("cmd-q", Quit, Some(CONTEXT)),
    ]);
}

impl Render for Editor {
    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
        div()
            .key_context(CONTEXT)
            .on_action(cx.listener(Self::move_up))
            .on_action(cx.listener(Self::move_down))
            .on_action(cx.listener(Self::save))
    }
}

impl Editor {
    fn move_up(&mut self, _: &MoveUp, cx: &mut Context<Self>) {
        // Handle move up
        cx.notify();
    }

    fn move_down(&mut self, _: &MoveDown, cx: &mut Context<Self>) {
        cx.notify();
    }

    fn save(&mut self, _: &Save, cx: &mut Context<Self>) {
        // Save logic
        cx.notify();
    }
}

Actions with Parameters

#[derive(Clone, PartialEq, Action, Deserialize)]
#[action(namespace = editor)]
pub struct InsertText {
    pub text: String,
}

#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
#[action(namespace = editor, no_json)]
pub struct Digit(pub u8);

cx.bind_keys([
    KeyBinding::new("0", Digit(0), Some(CONTEXT)),
    KeyBinding::new("1", Digit(1), Some(CONTEXT)),
    // ...
]);

impl Editor {
    fn on_digit(&mut self, action: &Digit, cx: &mut Context<Self>) {
        self.insert_digit(action.0, cx);
    }
}

Key Formats

// Modifiers
"cmd-s"         // Command (macOS) / Ctrl (Windows/Linux)
"ctrl-c"        // Control
"alt-f"         // Alt
"shift-tab"     // Shift
"cmd-ctrl-f"    // Multiple modifiers

// Keys
"a-z", "0-9"    // Letters and numbers
"f1-f12"        // Function keys
"up", "down", "left", "right"
"enter", "escape", "space", "tab"
"backspace", "delete"
"-", "=", "[", "]", etc.  // Special characters

Action Naming

Prefer verb-noun pattern:

actions!([
    OpenFile,      // ✅ Good
    CloseWindow,   // ✅ Good
    ToggleSidebar, // ✅ Good
    Save,          // ✅ Good (common exception)
]);

Context-Aware Bindings

const EDITOR_CONTEXT: &str = "Editor";
const MODAL_CONTEXT: &str = "Modal";

// Same key, different contexts
cx.bind_keys([
    KeyBinding::new("escape", CloseModal, Some(MODAL_CONTEXT)),
    KeyBinding::new("escape", ClearSelection, Some(EDITOR_CONTEXT)),
]);

// Set context on element
div()
    .key_context(EDITOR_CONTEXT)
    .child(editor_content)

Best Practices

✅ Use Contexts

// ✅ Good: Context-aware
div()
    .key_context("MyComponent")
    .on_action(cx.listener(Self::handle))

✅ Name Actions Clearly

// ✅ Good: Clear intent
actions!([
    SaveDocument,
    CloseTab,
    TogglePreview,
]);

✅ Handle with Listeners

// ✅ Good: Proper handler naming
impl MyComponent {
    fn on_action_save(&mut self, _: &Save, cx: &mut Context<Self>) {
        // Handle save
        cx.notify();
    }
}

div().on_action(cx.listener(Self::on_action_save))

Reference Documentation

  • Complete Guide: See reference.md
    • Action definition, keybinding, dispatch
    • Focus-based routing, best practices
    • Performance, accessibility

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/gpui-actions-and-keyboard-shortcuts-mveraop0/download' --output '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md.part' && mv '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md.part' '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md' && test -s '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/gpui-action' && cp -R '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0' '.claude/skills/gpui-action'

Cursor
test -f '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md' && test -s '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/gpui-action' && cp -R '.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0' '.cursor/skills/gpui-action'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0'

openskills read 'gpui-actions-and-keyboard-shortcuts-mveraop0'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/gpui-actions-and-keyboard-shortcuts-mveraop0/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills