Inline Completion and Chat

Inline Completion and Chat

These are the two tools you will use dozens of times every day. Mastering them is the core skill of working with Cursor.

Inline completion: how it really works

When you type, Cursor sends the current file (and sometimes nearby open files) to the model as context. The model predicts what comes next and streams the suggestion back as gray ghost text. It happens in milliseconds on fast connections.

The suggestion is not just the next word — it can be multiple lines, a whole function body, a complete if/else block, or a list of similar items following a pattern.

Accepting parts of a suggestion

You do not have to accept the whole suggestion. On macOS, Cmd + Right Arrow accepts the next word of the suggestion. This lets you pick through it one word at a time if the suggestion is mostly right but needs tweaks.

When completion shines

Boilerplate: Writing a REST endpoint you have written a dozen times, a React component shell, a database migration, a test file header. The AI fills in the structure; you fill in the specific logic.

Continuing a pattern: You write two or three items in a list, enum, or switch statement. The AI infers the pattern and suggests the next items. Accept them, then edit the specific values.

Comment-driven development: Write a detailed comment describing what you want, then press Enter. The AI uses the comment as a specification:

typescript
// Validate that an email address has a valid format. // Return true if valid, false otherwise. // Use a simple regex: must contain @ and a dot after it. function validateEmail(email: string): boolean {

After that comment and function signature, the AI will suggest the body.

Test writing: Write the name of a test case and the AI often suggests the whole test:

python
def test_empty_list_returns_zero():

The AI sees test_empty_list_returns_zero and infers you want to test that your function returns 0 for an empty list.

When completion fails

  • Long, complex algorithmic functions. The AI does not "think" — it guesses. For anything requiring careful logic (sorting, graph traversal, cryptography), write the outline yourself and use Chat instead.
  • When the suggestion keeps offering the same wrong thing. Press Escape, type a few more characters to guide it, and see if the next suggestion improves.
  • When the relevant code is in a different file that is not open. Open that file in a tab so Cursor includes it in the context window.

Chat: your AI pair programmer

Chat (Cmd/Ctrl + L) opens a panel where you have a proper conversation with the AI. You can attach context, ask follow-up questions, and apply suggested code with one click.

Attaching context

This is the most important skill in Chat. Without good context, the AI invents answers. With good context, it gives precise, relevant responses.

Attach the current file: In the chat input, type @ and the file name appears. Select it. Now the AI reads the whole file.

Attach a selection: Select code in the editor, then open Chat. The selection is automatically attached.

Attach a folder: Type @FolderName to give the AI an overview of all files in that folder. Useful when asking "how does this module work?"

Attach a symbol: Type @SymbolName (a function or class name) and the AI finds its definition across your project.

Types of questions to ask in Chat

Explain: "Explain what this function does, line by line." The AI gives a plain-English walkthrough. Useful for reading unfamiliar code or onboarding to a project.

Debug: Paste the error message. "I'm getting this error when I call processPayment(). What is the cause and how do I fix it?" The AI reads the attached code and the error and diagnoses the problem.

Refactor: "Refactor this function to be more readable. Extract the validation logic into a separate helper. Keep the same behavior." The AI proposes a refactored version; you click Apply to insert it.

Generate: "Write a function that takes a list of User objects and returns only the active ones, sorted by last login date descending." Give input, output, and rules; the AI writes the code.

Review: "Review this function for potential bugs, edge cases, and performance issues." The AI acts as a code reviewer.

Iteration is normal

Rarely does the first answer require zero changes. That is fine. Cursor chat is a conversation:

  1. Ask the question.
  2. Read the answer. If it missed something or is wrong, say so: "This does not handle the case where the list is empty. Fix that."
  3. The AI corrects. Maybe one more round. Done.

Three rounds of back-and-forth is often faster than writing the code yourself from scratch.

Applying code from Chat

When the AI suggests code in a code block, a small "Apply" or "Insert" button appears above it. Click it and Cursor opens a diff view showing what would change. You can accept the whole diff, accept individual hunks, or reject and try again.

Never accept blind. Read the diff. It takes thirty seconds and can save an hour of debugging.