Chat & Inline Editing
Learning Outcomes
- Use the AI side pane for multi-turn coding conversations
- Apply inline editing (Cmd+K) for quick, targeted changes
- Select code to provide precise context to the AI
- Accept, reject, and modify AI suggestions confidently
- Choose between Chat and inline edit based on the task
Lesson Plan
| Segment | Duration | Topic |
|---|---|---|
| Intro | 3 min | When to use Chat vs Inline Edit |
| Demo 1 | 10 min | AI side pane — multi-turn conversation workflow |
| Explain | 4 min | How context flows through a chat session |
| Demo 2 | 10 min | Inline editing — selection, prompt, review, accept |
| Demo 3 | 8 min | Combining both: ask in Chat, apply with Cmd+K |
| Explain | 5 min | Multi-file context with @file references |
| Wrap-up | 5 min | Decision framework and key takeaways |
Before You Begin
Pre-work:
- Complete Lesson 1 — The Cursor Interface
- Have a project open in Cursor with at least 2-3 files
Shopping List:
- Cursor open with a project
- A file you'd like to improve (any language)
- Familiarity with Cmd+L (Chat) and Cmd+K (Inline Edit) from Lesson 1
The AI side pane excels at tasks that require back-and-forth discussion, exploration, or multi-step reasoning.
Open Chat with Cmd+L. If you have code selected when you press Cmd+L, that selection is automatically attached as context.
Open Chat with Ctrl+L. If you have code selected when you press Ctrl+L, that selection is automatically attached as context.
Best use cases for Chat:
- Explaining complex code or architecture
- Planning a feature before writing code
- Debugging — describing a problem and iterating on solutions
- Asking "how should I approach X?" questions
- Generating boilerplate that you'll refine through conversation
Multi-turn workflow example:
You: How is authentication handled in this project?
AI: [Explains the auth flow based on your codebase]
You: I want to add rate limiting to the login endpoint. What's the best approach?
AI: [Suggests approaches, considering your existing stack]
You: Let's go with approach 2. Can you write the middleware?
AI: [Generates the code with an Apply button]
Notice how each message builds on the previous context. The AI remembers everything discussed in the current session.
Applying code from Chat:
When the AI generates code in the AI side pane, you'll see an Apply button above code blocks. Click it to:
- Insert the code at your cursor position, or
- Replace selected code in the editor, or
- Create a new file with the generated content
Inline editing (Cmd+K / Ctrl+K) is for quick, surgical changes where you know exactly what you want and where you want it.
The inline edit workflow:
- Select code (optional — selecting gives more context)
- Press Cmd+K — the inline prompt bar appears
- Type your instruction — be concise and specific
- Press Enter — the AI generates a diff
- Review the green/red diff highlighting
- Press Tab to accept, or Escape to reject
The inline edit workflow:
- Select code (optional — selecting gives more context)
- Press Ctrl+K — the inline prompt bar appears
- Type your instruction — be concise and specific
- Press Enter — the AI generates a diff
- Review the green/red diff highlighting
- Press Tab to accept, or Escape to reject
Effective inline edit prompts:
| Prompt | What It Does |
|---|---|
| "Add error handling" | Wraps selected code in try/catch |
| "Make this async" | Converts function to async/await |
| "Add TypeScript types" | Adds type annotations to parameters and returns |
| "Simplify this logic" | Refactors to clearer, shorter code |
| "Add logging" | Inserts console.log or logger statements |
| "Convert to arrow function" | Transforms function syntax |
Generating new code (no selection):
If you press Cmd+K / Ctrl+K without selecting anything, the AI generates new code at the cursor position. This is useful for:
- "Write a function that validates email addresses"
- "Add an import for React useState"
- "Create a test case for the above function"
The generated code appears as a diff — green lines showing what will be inserted.
Iterating on inline edits:
If the first result isn't quite right but is close:
- Accept the edit (Tab)
- Select the result
- Press Cmd+K / Ctrl+K again
- Refine: "Almost — but use a Map instead of an object"
This iterative approach is often faster than crafting one perfect prompt.
The code you select before triggering AI is crucial — it determines what the AI understands about your intent.
Selection strategies:
| What You Select | When to Use It |
|---|---|
| Nothing (cursor on a line) | Generating new code at that position |
| A single line | Fixing or modifying one statement |
| A function body | Refactoring logic within a function |
| An entire function (including signature) | Rewriting, adding docs, or explaining |
| Multiple functions | When they're related and need coordinated changes |
| An entire file | When asking about architecture or doing large rewrites |
How to select effectively:
- Select current line: Cmd+L (note: this also opens Chat if no selection — select first with Cmd+Shift+K or use your mouse)
- Select word: Double-click or Cmd+D
- Expand selection: Cmd+Shift+Arrow keys
- Select function: Click the function name, then Cmd+Shift+] to select the enclosing block
- Select all occurrences: Cmd+Shift+L (select all matching text)
- Select current line: Ctrl+L
- Select word: Double-click or Ctrl+D
- Expand selection: Ctrl+Shift+Arrow keys
- Select function: Click the function name, then Ctrl+Shift+] to select the enclosing block
- Select all occurrences: Ctrl+Shift+L (select all matching text)
Context in Chat vs Inline:
- Cmd+K (Inline): Only the selected code and the current file are visible to the AI
- Cmd+L (Chat): The selected code is attached, but the AI can also reference other files in the project
This is why Chat is better for cross-file tasks and Inline is better for focused, single-location edits.
Every AI suggestion in Cursor requires your explicit approval. Here's how to handle each response:
For Inline Edits (Cmd+K):
| Action | How | When |
|---|---|---|
| Accept all | Tab | The diff looks correct |
| Reject all | Escape | The change is wrong — start over |
| Accept partially | Select lines, then Tab | Only some changes are correct |
| Re-prompt | Type in the prompt bar again | Close but needs adjustment |
For Chat suggestions:
| Action | How | When |
|---|---|---|
| Apply to editor | Click "Apply" on the code block | Code looks good, want to insert it |
| Copy | Click the copy icon on the code block | Want to paste manually |
| Iterate | Send a follow-up message | Need changes before applying |
| Ignore | Just continue the conversation | The code wasn't what you wanted |
The diff view in detail:
When an inline edit generates a diff:
- Red background = lines being removed
- Green background = lines being added
- No background = unchanged context lines
- The left gutter shows
−and+markers
You can scroll through multi-section diffs using the up/down arrows in the diff toolbar.
Undoing accepted changes:
If you accept a change and then realize it was wrong:
Press Cmd+Z immediately — Cursor treats the entire AI edit as a single undo step.
Press Ctrl+Z immediately — Cursor treats the entire AI edit as a single undo step.
Choosing the right tool for the task saves time and produces better results:
Use Chat (Cmd+L / Ctrl+L) when:
- You need to explain or understand code
- The task requires planning before coding
- You want to discuss trade-offs between approaches
- The change involves multiple files or complex logic
- You're debugging and need to iterate on the problem description
- You want to generate a new file from scratch
Use Inline Edit (Cmd+K / Ctrl+K) when:
- You know exactly what change you want
- The change is localized to one spot in one file
- You want a quick transformation (add types, rename, convert syntax)
- You're iterating rapidly — make a change, test, adjust
- The instruction fits in a short sentence
Decision flowchart:
- Can you describe the change in one short sentence? → Inline Edit
- Do you need to ask questions first? → Chat
- Is it a single-file change? → Inline Edit
- Does it span multiple files? → Chat (or Agent)
- Are you exploring/learning? → Chat
- Are you executing a known change? → Inline Edit
Combining both — the power workflow:
- Open Chat, ask: "How should I add validation to the user signup form?"
- Review the AI's suggested approach
- Navigate to the file mentioned
- Select the relevant function
- Press Cmd+K: "Add validation for email, password length > 8, and required fields"
- Accept the inline change
- Back in Chat: "Now I need the matching error messages in the response"
This workflow uses Chat for thinking and Inline for doing.
Chat becomes dramatically more useful when you give it context about multiple files. Use the @ symbol in the chat input to reference files, symbols, and more.
Basic @file references:
In the Chat input, type @ followed by a filename:
@src/auth/login.js I want to add rate limiting to this endpoint.
How should I implement it given the existing middleware pattern?
The AI will read the referenced file and use it as context for its response.
Multiple file references:
@src/models/user.js @src/routes/auth.js @src/middleware/validate.js
These three files handle user authentication. I want to add
two-factor authentication. What changes are needed in each file?
How to use @file effectively:
- Type
@in the chat input - Start typing the filename — Cursor shows autocomplete suggestions
- Select the file from the dropdown
- The file appears as a pill/chip in the context bar above the input
- Type your question or instruction
What you can reference with @:
| Syntax | What It References |
|---|---|
@filename |
A specific file in the workspace |
@folder/ |
All files in a folder |
@symbolName |
A function, class, or variable by name |
Agent mode |
The entire indexed codebase |
@docs |
Documentation sources |
| `` | Search the web for context |
Removing context:
Click the X on any context chip to remove it from the conversation. This helps if you've attached too many files and the AI is getting confused.
Questions & Answers
Key Takeaways
- Chat (Cmd+L / Ctrl+L) is for conversation, exploration, and multi-file tasks
- Inline Edit (Cmd+K / Ctrl+K) is for quick, targeted, single-location changes
- Selection matters — the code you select determines the AI's context and the scope of the edit
- Always review diffs before accepting — Tab to accept, Escape to reject
- Use @file references in Chat to give the AI awareness of specific files
- Combine both tools — use Chat to plan, Inline Edit to execute
Next Steps: In Lesson 3 — Tab Completion & Predictions, you'll learn how Cursor's AI-powered autocomplete anticipates what you'll type next.