Beginner15 min1 prerequisite

Master Cursor's intelligent Tab completion to write code faster with AI-powered suggestions.

Tab Completion in Cursor

Tab completion is Cursor's most frequently used AI feature. As you type, Cursor predicts what you want to write next and shows suggestions in ghosted text. Press Tab to accept, or keep typing to ignore.

How Tab Completion Works

The Ghost Text

As you type, you'll notice faded gray text appearing after your cursor:

Terminal
function calculateTotal(items) {
  // You type: "return items"
  // Ghost text appears: ".reduce((sum, item) => sum + item.price, 0)"
}

This ghost text is Cursor's prediction of what you want to write next. It's based on:

  • Your current file context
  • The function or code block you're in
  • Patterns from your codebase
  • Common programming conventions

Accepting Suggestions

Full acceptance: Press Tab to accept the entire suggestion.

Partial acceptance: Press Ctrl+Right Arrow (Windows/Linux) or Cmd+Right Arrow (Mac) to accept word by word.

Reject: Keep typing or press Escape to dismiss the suggestion.

Types of Completions

Single-Line Completions

The most common type—completing a line of code:

Terminal
# You type: "def validate_email"
# Suggestion: "(email: str) -> bool:"

# You type: "if user.is_authenticated"
# Suggestion: " and user.has_permission('admin'):"

Multi-Line Completions

Cursor can suggest entire code blocks:

Terminal
// You type: "interface User {"
// Suggestion appears:
//   id: string
//   name: string
//   email: string
//   createdAt: Date
// }

Comment-Driven Completions

Write a comment describing what you want, then press Enter:

Terminal
// Function to validate email format using regex
// Press Enter, and Cursor suggests:
function validateEmail(email) {
  const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
  return regex.test(email)
}

Effective Tab Completion Techniques

Technique 1: Descriptive Naming

Use clear, descriptive names—Cursor infers intent from them:

Terminal
# Vague name = generic suggestion
def process(data):
    # Cursor has less context

# Descriptive name = better suggestion
def calculate_monthly_revenue(transactions):
    # Cursor suggests relevant revenue calculation logic

Technique 2: Type Hints

Adding types gives Cursor more context:

Terminal
// Without types
function getUser(id) {
  // Less specific suggestions
}

// With types
function getUser(id: string): Promise<User | null> {
  // Cursor suggests proper async/await pattern with error handling
}

Technique 3: Leading Comments

Guide completions with comments:

Terminal
# Fetch all active users from database, sorted by creation date
def get_active_users():
    # Cursor now knows exactly what to suggest

Technique 4: Partial Code

Start a pattern and let Cursor continue:

Terminal
const routes = {
  home: '/',
  about: '/about',
  // Cursor suggests more routes based on common patterns
}

Configuring Tab Completion

Enable/Disable

Open Settings (Cmd+, or Ctrl+,) and search for "Cursor Tab":

  • Cursor Tab: Toggle AI completions on/off
  • Show suggestions automatically: Enable or require manual trigger

Suggestion Timing

Adjust how quickly suggestions appear:

  • Delay: How long to wait before showing suggestions (default: 200ms)
  • Debounce: Prevent suggestions while actively typing

Completion Length

Control suggestion length:

  • Max lines: Limit multi-line suggestions
  • Conservative mode: Shorter, more confident suggestions

Tab vs Other Completion Sources

Cursor combines multiple suggestion sources:

SourceTriggerBest For
Tab (AI)AutomaticContext-aware code
IntelliSense. or Ctrl+SpaceAPI exploration
SnippetsKeyword + TabBoilerplate code
EmmetAbbreviation + TabHTML/CSS

Priority

When multiple sources have suggestions:

  1. AI Tab completions appear as ghost text
  2. IntelliSense appears in a dropdown
  3. You can use either independently

Troubleshooting

Suggestions Not Appearing

  1. Check if Tab completion is enabled in settings
  2. Verify you're not in a restricted file type
  3. Check your internet connection (AI features require it)
  4. Restart Cursor

Suggestions Are Wrong

If suggestions aren't relevant:

  1. Add more context (comments, types)
  2. Open related files (Cursor considers open tabs)
  3. Use more specific naming
  4. Check if the file is part of your workspace

Suggestions Are Slow

To speed up suggestions:

  1. Reduce project size in workspace
  2. Add files to .cursorignore that AI shouldn't index
  3. Check network connection speed

Tab Completion vs Chat

When to use each:

Use Tab Completion for:

  • Completing code as you type
  • Following established patterns
  • Writing routine code quickly
  • Minor code generation

Use Chat for:

  • Explaining code decisions
  • Complex logic generation
  • Debugging and understanding
  • Multi-step code changes

Practice Exercise

Try this exercise to build muscle memory:

  1. Create a new TypeScript file
  2. Type: // Function to format currency with locale support
  3. Press Enter
  4. Accept Tab suggestions to build the function
  5. Add another comment: // Format as US dollars
  6. Let Cursor complete a usage example

Summary

  • Ghost text shows AI predictions as you type
  • Press Tab to accept full suggestions
  • Press Cmd+Right for word-by-word acceptance
  • Use descriptive names and comments for better suggestions
  • Configure settings to match your preferences
  • Combine with IntelliSense for comprehensive completions

Next Steps

Tab completion handles in-line suggestions. For more targeted editing—like modifying existing code—you'll use Cursor's inline editing feature.

Mark this lesson as complete to track your progress