- Learn
- AI Code Editors
- Cursor
- Tab Completion in Cursor
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:
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:
# 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:
// 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:
// 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:
# 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:
// 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:
# 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:
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:
| Source | Trigger | Best For |
|---|---|---|
| Tab (AI) | Automatic | Context-aware code |
| IntelliSense | . or Ctrl+Space | API exploration |
| Snippets | Keyword + Tab | Boilerplate code |
| Emmet | Abbreviation + Tab | HTML/CSS |
Priority
When multiple sources have suggestions:
- AI Tab completions appear as ghost text
- IntelliSense appears in a dropdown
- You can use either independently
Troubleshooting
Suggestions Not Appearing
- Check if Tab completion is enabled in settings
- Verify you're not in a restricted file type
- Check your internet connection (AI features require it)
- Restart Cursor
Suggestions Are Wrong
If suggestions aren't relevant:
- Add more context (comments, types)
- Open related files (Cursor considers open tabs)
- Use more specific naming
- Check if the file is part of your workspace
Suggestions Are Slow
To speed up suggestions:
- Reduce project size in workspace
- Add files to
.cursorignorethat AI shouldn't index - 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:
- Create a new TypeScript file
- Type:
// Function to format currency with locale support - Press Enter
- Accept Tab suggestions to build the function
- Add another comment:
// Format as US dollars - 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.