Chat & Inline Editing

45 min beginner Lesson 2

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:

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

1 Chat Panel — Multi-Turn Conversations

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
TIP
Tip
Start a new chat for each distinct task. Use the + button at the top of the AI side pane. This keeps context focused and prevents the AI from getting confused by unrelated earlier messages.

2 Inline Editing — Quick, Focused Changes

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:

  1. Select code (optional — selecting gives more context)
  2. Press Cmd+K — the inline prompt bar appears
  3. Type your instruction — be concise and specific
  4. Press Enter — the AI generates a diff
  5. Review the green/red diff highlighting
  6. Press Tab to accept, or Escape to reject

The inline edit workflow:

  1. Select code (optional — selecting gives more context)
  2. Press Ctrl+K — the inline prompt bar appears
  3. Type your instruction — be concise and specific
  4. Press Enter — the AI generates a diff
  5. Review the green/red diff highlighting
  6. 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.

WARNING
Watch Out
If the diff looks wrong, press Escape immediately. Don't accept partial changes hoping to fix them later — it's faster to reject and re-prompt with a clearer instruction.

Iterating on inline edits:

If the first result isn't quite right but is close:

  1. Accept the edit (Tab)
  2. Select the result
  3. Press Cmd+K / Ctrl+K again
  4. Refine: "Almost — but use a Map instead of an object"

This iterative approach is often faster than crafting one perfect prompt.


3 Selecting Code for Context

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.

TIP
Tip
When using Cmd+K, select slightly more code than you think you need. Including the function signature above or the closing brace below helps the AI understand the full context of what it's modifying.

4 Accepting, Rejecting, and Modifying Suggestions

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.

NOTE
How It Works
Cursor groups the entire AI-generated change into one undo operation. Even if 20 lines were modified, a single Cmd+Z / Ctrl+Z reverts them all back to the previous state.
WARNING
Watch Out
Don't manually edit the diff view. Wait until you've accepted or rejected the AI suggestion, then make manual edits. Editing during diff review can cause unexpected results.

5 Chat vs Inline — When to Use Each

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:

  1. Can you describe the change in one short sentence? → Inline Edit
  2. Do you need to ask questions first? → Chat
  3. Is it a single-file change? → Inline Edit
  4. Does it span multiple files? → Chat (or Agent)
  5. Are you exploring/learning? → Chat
  6. Are you executing a known change? → Inline Edit

Combining both — the power workflow:

  1. Open Chat, ask: "How should I add validation to the user signup form?"
  2. Review the AI's suggested approach
  3. Navigate to the file mentioned
  4. Select the relevant function
  5. Press Cmd+K: "Add validation for email, password length > 8, and required fields"
  6. Accept the inline change
  7. Back in Chat: "Now I need the matching error messages in the response"

This workflow uses Chat for thinking and Inline for doing.

TIP
Tip
When in doubt, start with Chat. If the AI gives you a clear, simple code block — next time you need the same kind of change, you'll know to use Inline Edit directly.

6 Multi-File Context in Chat (@file References)

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:

  1. Type @ in the chat input
  2. Start typing the filename — Cursor shows autocomplete suggestions
  3. Select the file from the dropdown
  4. The file appears as a pill/chip in the context bar above the input
  5. 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.

NOTE
How It Works
When you @-reference a file, Cursor reads its full content and includes it in the prompt sent to the AI model. More files = more context used from your token budget, so be selective.
WARNING
Watch Out
Don't attach too many files at once. If you reference 10+ large files, you may hit context limits and the AI's responses will degrade. Reference only the files directly relevant to your question.

Questions & Answers

Q: Can I use Chat and Inline Edit in the same session?
Absolutely. They're independent tools. You can have a Chat conversation open while using Cmd+K for inline edits. The Chat doesn't see your inline edits (they're separate contexts), but you can reference the results by selecting the newly edited code and pressing Cmd+L to add it to Chat.
Q: Is there a limit to how long a chat conversation can be?
Yes — each AI model has a context window limit. When your conversation gets long, Cursor handles this by summarizing older messages. You'll see a "context compressed" notice. For very long tasks, consider starting a new chat and referencing files fresh rather than continuing indefinitely.
Q: Can I edit the AI's code before accepting it?
For inline edits, you should accept or reject first, then edit manually. For Chat code blocks, you can copy the code, paste it into your editor, and modify it by hand — or ask the AI to revise it before applying. You cannot directly edit within the diff view.
Q: Do @file references work in inline edit (Cmd+K)?
No. The @-mention syntax only works in the AI side pane. Inline edit uses only the selected code and the current file as context. If you need multi-file awareness for a change, use Chat instead.

Key Takeaways

  1. Chat (Cmd+L / Ctrl+L) is for conversation, exploration, and multi-file tasks
  2. Inline Edit (Cmd+K / Ctrl+K) is for quick, targeted, single-location changes
  3. Selection matters — the code you select determines the AI's context and the scope of the edit
  4. Always review diffs before accepting — Tab to accept, Escape to reject
  5. Use @file references in Chat to give the AI awareness of specific files
  6. 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.