Cursor Tutorial - How to Use the Tab?

Cursor, an AI-powered coding assistant, offers three main features:

  1. Tab completion
  2. Prompt Bars (Cmd + K)
  3. Chat (Cmd + L)

Today, we’ll focus on the Tab feature - the one that really shows off Cursor’s magic.

Why do different AI code editors all have Tab features, but the experience varies so much? What makes Cursor’s Tab feature special?

What is the Tab Feature?

What’s the simplest way for AI to help with coding? It’s when the AI understands your code’s context and automatically suggests code completions that you can accept with just a Tab key.

I can’t think of a more straightforward way to assist with coding. Users don’t need to describe what they want - the AI just provides suggestions. It’s the most natural and direct way to help.

Cursor’s Tab feature is exactly this kind of coding assistant. Compared to GitHub Copilot and MarsCode, Cursor’s biggest advantage is its code editing ability. It doesn’t just insert new code - it can modify existing code too. Cursor emphasizes this in their official documentation:

Cursor's code modification ability

You can find a more detailed comparison in my previous post Why I Switched from Github Copilot?.

Basic Tab Features

Multi-line Completion

The most basic feature is code generation - it suggests code completions based on your cursor position. Here’s an example:

Cursor's code generation

In this example, you might have only typed the function definition and the first line, but Cursor’s Tab feature can intelligently complete the rest of the code.

But Cursor’s Tab feature goes beyond that - it supports multi-line editing and can generate suggestions for multiple lines at once. Like this:

Cursor's multi-line completion

The Tab feature generates multi-line code suggestions based on your current cursor position. In the example above, when you type “Block”, it suggests similar completions for other related parts.

Note that in these examples, Tab shows its code completion suggestions in gray text.

Advanced Tab Features

Smart Rewrite

Cursor’s Tab feature isn’t just about simple code completion. It can intelligently rewrite your existing code - this is Cursor’s proudest feature. Whether it’s small changes or major refactoring, this feature comes in handy.

Cursor's smart rewrite

When rewriting code, Cursor shows its suggestions in a prompt box instead of the gray inline suggestions used for completions.

Cursor Prediction

The features we’ve discussed so far are based on your current cursor position and the surrounding code context.

But Cursor goes even further.

It can predict where you might want to edit next. This powerful feature is called “cursor prediction” (Now I think I know why they named it Cursor!)

Cursor's prediction feature

In this example, when you change a function’s name, Cursor predicts that the function name in the red circle below should also change.

Cursor prediction example 2

Similarly, in this example, when you rename the ‘updates’ variable to ‘updatesToServer’, Cursor predicts that the ‘updates’ variable below should also be updated to ‘updatesToServer’.

Pro Tips

Tab in Peek

Cursor’s Tab feature works not just in the main editor window, but also in “Go to Definition” or “Go to Type Definition” preview windows. This is especially useful when adding new function parameters.

For example, when you need to modify a function definition and quickly fix all its usages, this feature is super handy. It’s particularly useful for vim users who can combine it with the gd command to modify function definitions and quickly fix all call sites.

Using Tab in preview windows

In this example, we can see how users can use the Tab feature in preview windows to modify function definitions and add new parameters.

This feature makes code refactoring more efficient, making it easier and faster to add new features or modify existing interfaces.

Partial Accepts

You can accept the next word of a suggestion by pressing Ctrl/⌘ and the right arrow key. This gives you finer control over the code completion process.

The Future of Tab Feature

From a user experience perspective, there’s still room for improvement in Tab’s context understanding. For instance, when switching back to the current file after modifying code in other files, the Tab suggestions tend to be less accurate.

According to Cursor’s blog post on Next Action Prediction, the Tab feature will eventually support cross-file code generation suggestions, not just suggestions within the current file. This means Cursor will better understand the entire project’s context and provide more accurate and useful code suggestions.

Summary

Overall, Cursor’s Tab feature is a powerful and intuitive AI coding assistant. This tutorial should give you a good understanding of its capabilities.

But Cursor’s power isn’t as simple as it seems. Deep research reveals that the Cursor team has put in extensive work on improvements and optimizations.

Cursor’s Tab feature uses their own custom-trained model. Their blog discusses many details about model training methods and optimizations - check it out if you’re interested.