SOP-005: Inline Edit (Cmd+K)
Document Control
| Field | Value |
|---|---|
| SOP ID | SOP-005 |
| Version | 1.0 |
| Status | Active |
| Last Updated | 2024-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:
| Mode | When to Use |
|---|---|
| Edit Selection | Code is selected → modify it |
| Generate | No selection → create new code at cursor |
Shortcut: Cmd+K / Ctrl+K opens the input bar
Three Actions:
| Shortcut | Action |
|---|---|
Enter | Apply changes |
Alt+Enter | Quick Question (no changes) |
Cmd+Shift+Enter | Full File Edit |
Step 1: Edit Selected Code
Shortcut: Cmd+K / Ctrl+K
- Select the code you want to modify
- Press
Cmd+K/Ctrl+K - Type your instruction (e.g., "add error handling")
- Press
Enterto apply
Example:
// 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:
- Place cursor where you want new code
- Press
Cmd+K/Ctrl+K - Type what you want to create
- Press
Enter
Example:
// 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:
- Select code (optional)
- Press
Cmd+K/Ctrl+K - Type your question
- Press
Alt+Enter(not regular Enter)
Quick Question Flow:
- Select code (optional)
- Press
Cmd+K/Ctrl+K - Type your question
- Press
Alt+Enter - AI explains the code inline
- 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:
- Press
Cmd+K/Ctrl+K - Type your instruction
- 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:
- Initial Request: "add logging" → Result: console.log statements added
- Follow-up: "use winston logger instead" → Result: Updated to use winston
- 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:
- Select code
- Press
Cmd+L/Ctrl+L - Code is sent to Agent Chat
- Agent can then edit multiple files
Default Context
Inline Edit automatically includes:
| Context Type | Description |
|---|---|
| Selected code | What you selected |
| Surrounding code | Context around selection |
| Recent changes | Your recent edits |
| Related files | Imported/related files |
| @ Mentions | Any @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
| Action | Shortcut |
|---|---|
| Open Inline Edit | Cmd+K / Ctrl+K |
| Apply changes | Enter |
| Cancel | Escape |
| Quick Question | Alt+Enter |
| Full File Edit | Cmd+Shift+Enter |
| Send to Chat | Cmd+L / Ctrl+L |
| Toggle input focus | Cmd+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
| Issue | Solution |
|---|---|
| Cmd+K not working | Check for conflicting keybindings |
| Changes not applying | Press Enter, not just close prompt |
| Wrong modifications | Be more specific in instructions |
| Missing context | Add @mentions for relevant files |
| Full file edit too aggressive | Use selection edit instead |