Skip to content

SOP-005: Inline Edit (Cmd+K)

Document Control

FieldValue
SOP IDSOP-005
Version1.0
StatusActive
Last Updated2024-12

Purpose

This SOP covers using Cursor's Inline Edit feature (Cmd+K) to edit code directly in your editor using natural language.

Scope

  • Selection editing
  • Code generation
  • Quick questions
  • Full file edits

Prerequisites

  • Cursor installed and configured
  • Active code file open

Procedure

Inline Edit Overview

Two Starting Points:

ModeWhen to Use
Edit SelectionCode is selected → modify it
GenerateNo selection → create new code at cursor

Shortcut: Cmd+K / Ctrl+K opens the input bar

Three Actions:

ShortcutAction
EnterApply changes
Alt+EnterQuick Question (no changes)
Cmd+Shift+EnterFull File Edit

Step 1: Edit Selected Code

Shortcut: Cmd+K / Ctrl+K

  1. Select the code you want to modify
  2. Press Cmd+K / Ctrl+K
  3. Type your instruction (e.g., "add error handling")
  4. Press Enter to apply

Example:

javascript
// Select this function:
function divide(a, b) {
  return a / b;
}

// Press Cmd+K, type: "add error handling for division by zero"
// Result:
function divide(a, b) {
  if (b === 0) {
    throw new Error('Cannot divide by zero');
  }
  return a / b;
}

Step 2: Generate New Code

Without any selection, Cmd+K generates code at your cursor position:

  1. Place cursor where you want new code
  2. Press Cmd+K / Ctrl+K
  3. Type what you want to create
  4. Press Enter

Example:

javascript
// Cursor is here, press Cmd+K
// Type: "create a function to validate email addresses"
// Result:
function validateEmail(email) {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailRegex.test(email);
}

Context Awareness

Even without selection, Cursor considers surrounding code for context. If you're in a class, it generates class-appropriate code.

Step 3: Quick Question (Alt+Enter)

Ask questions about code without modifying it:

  1. Select code (optional)
  2. Press Cmd+K / Ctrl+K
  3. Type your question
  4. Press Alt+Enter (not regular Enter)

Quick Question Flow:

  1. Select code (optional)
  2. Press Cmd+K / Ctrl+K
  3. Type your question
  4. Press Alt+Enter
  5. AI explains the code inline
  6. Want to apply? Type "do it"

Example Questions:

  • "What does this regex do?"
  • "Is this function secure?"
  • "How can I optimize this?"

Converting to Code: After getting an answer, type "do it" or "apply this" to convert the suggestion into actual code changes.

Step 4: Full File Edit (Cmd+Shift+Enter)

For comprehensive file-wide changes:

  1. Press Cmd+K / Ctrl+K
  2. Type your instruction
  3. Press Cmd+Shift+Enter / Ctrl+Shift+Enter

Use Cases:

  • "Convert all functions to arrow functions"
  • "Add TypeScript types to all parameters"
  • "Refactor to use async/await instead of promises"

Use with Caution

Full file edit modifies your entire file. Review changes carefully before accepting.

Step 5: Follow-Up Instructions

Refine results iteratively:

  1. Initial Request: "add logging" → Result: console.log statements added
  2. Follow-up: "use winston logger instead" → Result: Updated to use winston
  3. Follow-up: "add timestamp to each log" → Result: Timestamps added

Just type additional instructions and press Enter. The AI remembers context from previous edits.

Step 6: Send to Chat (Cmd+L)

For complex multi-file changes:

  1. Select code
  2. Press Cmd+L / Ctrl+L
  3. Code is sent to Agent Chat
  4. Agent can then edit multiple files

Default Context

Inline Edit automatically includes:

Context TypeDescription
Selected codeWhat you selected
Surrounding codeContext around selection
Recent changesYour recent edits
Related filesImported/related files
@ MentionsAny @files or @docs you add

Adding More Context

Type @ in the inline edit prompt to add:

  • @file.ts - Reference another file
  • @Docs - Use documentation

Keyboard Reference

ActionShortcut
Open Inline EditCmd+K / Ctrl+K
Apply changesEnter
CancelEscape
Quick QuestionAlt+Enter
Full File EditCmd+Shift+Enter
Send to ChatCmd+L / Ctrl+L
Toggle input focusCmd+Shift+K

Best Practices

DO:

  • Be specific in instructions ("add null check" → "add null check that throws Error")
  • Select appropriate scope (too little = missing context, too much = unfocused changes)
  • Use Quick Question first when unsure - understand before modifying
  • Review diffs before accepting - AI can make mistakes

DON'T:

  • Use for multi-file changes - use Agent Chat (Cmd+I) instead

Verification Checklist

  • [ ] Cmd+K opens inline edit prompt
  • [ ] Edit selection modifies selected code
  • [ ] Generate creates code at cursor without selection
  • [ ] Alt+Enter triggers Quick Question mode
  • [ ] Cmd+Shift+Enter triggers full file edit
  • [ ] Follow-up instructions refine results
  • [ ] Cmd+L sends to Agent Chat

Troubleshooting

IssueSolution
Cmd+K not workingCheck for conflicting keybindings
Changes not applyingPress Enter, not just close prompt
Wrong modificationsBe more specific in instructions
Missing contextAdd @mentions for relevant files
Full file edit too aggressiveUse selection edit instead

See Also

Built with VitePress | Powered by Claude AI