Aller au contenu

Leçon 4 · Completions and Inline Edits

Cursor Tab Completion

Use Cursor Tab: accept, reject and partly accept suggestions, follow jumps to your next edit, control where Tab runs, and write code that guides it.

Tab is the AI autocomplete built into Cursor. Instead of finishing only the word you are typing, it can propose several lines, or a change to code you already wrote. The documentation says it uses your recent edits, the surrounding code and linter errors.

Tab is the quickest feature to learn and also easy to use carelessly, because accepting a suggestion costs one key press. This lesson shows the keys, the controls and how to get better suggestions.

The basic keys

Suggestions appear as gray text ahead of your cursor. As of December 2026, the documentation lists these actions:

Action Windows and Linux macOS
Accept the whole suggestion Tab Tab
Reject it Esc, or keep typing Esc, or keep typing
Accept the next word only Ctrl+Right Arrow Cmd+Right Arrow

Partial acceptance is easy to forget. If a suggestion starts correctly and then goes wrong, take the good words one by one and type the rest yourself.

If Tab collides with indentation or another extension, you can remap the accept key in the keyboard shortcut settings.

Jumps: the next edit

Many edits come in groups. You rename a parameter, and three other lines must follow. After you accept a suggestion, pressing Tab again can jump to the place where Tab predicts your next edit. It can also predict edits in other files; when such a jump is available, a small preview window appears at the bottom of the editor.

Read each stop before you accept it. A chain of quick Tab presses is how a wrong change spreads through a file.

Where to be careful

Often easy to check

Repetitive edits
Missing imports
Familiar patterns
More test cases
1 / 2

Guide Tab with your code

You can steer Tab without any prompt, because the surrounding code is its main clue:

  1. Name things well. parse_iso_date tells more than handle.
  2. Write the signature and docstring first. State the input, the output and the edge cases.
  3. Show one example. After you write one item in a list or one test, the next ones are easier to predict.
  4. Add types. Type hints and clear data shapes remove guesses.
Python A signature and docstring that leave little to guess

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the docstring also gives you the test cases. If a suggested body does not satisfy them, reject it.

Test what looks obvious

Suggestions often look right at a glance. Here are two plausible ways to count pages, written for this lesson. Only one handles a list whose length is not a multiple of the page size.

Python Two plausible suggestions, one bug

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first version loses the last page when there are 11 items. A habit of testing the boundaries (zero, one less, exact, one more) catches this kind of error quickly.

Turn Tab down or off

Sometimes completions distract you, for example while writing prose or while you practice a new language. A Tab status indicator in the bottom-right corner of the editor lets you:

  • Snooze Tab for a chosen time.
  • Disable it everywhere.
  • Disable it for specific file extensions, such as Markdown or JSON.

You can also configure Tab in its section of the app settings.

If you are learning to program, try writing a function yourself first and then turn Tab on to compare. Accepting code you cannot explain does not teach you the language.

What Tab does not follow

Project rules, which you will meet in a later lesson, do not affect Tab. If Tab keeps suggesting a style your team does not use, rely on a formatter and a linter, and let the surrounding code set the example.

You can keep files away from Tab by listing them in .cursorignore. See ignore files. Sensitive files such as .env deserve that protection.

A habit for accepting code

Use a tiny routine before and after you press Tab:

  1. Read the whole gray text, including the last line.
  2. Compare it with your intent. Does it use the variable you meant?
  3. Check the unfamiliar. Hover over a function you do not know, or open its documentation.
  4. Run the code soon, while you still remember what you accepted.

Pay special attention to suggestions that copy a nearby block. Copies often keep one old name, such as start_date where you needed end_date. The code looks consistent and is easy to skim past.

Comments can be suggested too. A suggested comment may describe what the code should do rather than what it does. A wrong comment misleads the next reader, so check comments as carefully as code.

Common mistakes

  • Accepting a long suggestion without reading it.
  • Trusting a method name because it looks natural. Check your library's documentation.
  • Pressing Tab repeatedly through jumps. Stop and read each one.
  • Typing a real password or token into a source file. Keep secrets in a secret manager or in protected, ignored files.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. A suggestion starts well but ends badly. What is the best action?

    Partial acceptance keeps the useful beginning without taking the bad end.
  2. 2. What can pressing Tab again after accepting do?

    Tab can move you to the next place it expects you to edit. Read it before accepting.
  3. 3. How can you improve suggestions without writing a prompt?

    The surrounding code is the signal, so make your intent visible in it.
  4. 4. Do project rules change what Tab suggests?

    Use formatters, linters and good surrounding code to shape completions.

Summary

  • Tab accepts, Esc rejects, and Ctrl+Right Arrow accepts one word.
  • Jumps connect related edits; read each one.
  • Clear names, types and docstrings guide suggestions.
  • Test boundaries; plausible code can be wrong.
  • You can snooze or disable Tab, including per file type.

Next: Editing Selected Code

Votre progression est enregistrée dans ce navigateur. Aucun compte nécessaire.