What is the simplest and most straightforward form of AI-assisted programming? Why do different AI editors all implement the Tab feature, but the experiences vary so greatly? What capabilities does Cursor's Tab feature achieve?
Cursor's AI-assisted programming provides three main functions:
- Tab feature
- Hint box feature (Cmd + K)
- Chat feature (Cmd + L)
In this article, we mainly introduce Tab, the feature that allows users to most directly experience Cursor's magic.
Why do different AI editors all implement the Tab feature, but the experiences vary so greatly? What capabilities does Cursor's Tab feature achieve?
What is the Tab Feature
What is the simplest and most straightforward form of AI-assisted programming? It is actually to automatically generate code completion suggestions based on the current code context, and users can directly complete code modification and completion by pressing the Tab key.
I can't think of a simpler and more straightforward way of assisted programming than this. Users don't need to describe any requirements, and the AI directly provides suggestions for you. This is the most natural and direct way of assistance.
Cursor's Tab feature is exactly such an assisted programming tool. Compared with GitHub Copilot and Doubao MarsCode, Cursor's greatest advantage lies in its code editing ability. It can not only insert code but also modify existing code, which is also emphasized by Cursor in its official documentation many times:
Basic Tab Features
Multi-line Completion
The most basic function is code generation, which directly generates code completion suggestions based on the current cursor position. As shown in the following figure:
In this example, you may have only entered the function definition and the first line, and Cursor's Tab feature can intelligently complete the remaining code.
However, Cursor's Tab feature is not limited to this. It also supports multi-line editing and can directly generate multi-line code completion suggestions. As shown in the following figure:
The Tab feature will generate multi-line code completion suggestions based on the modifications at your current cursor position. In the above example, after you enter Block, similar places elsewhere will also prompt you to add Block.
Note that in the above example, when the Tab feature makes code completion suggestions, the suggested completed code is displayed in gray code.
Advanced Tab Features
Smart Rewrite
Cursor's Tab feature is not just simple code completion. It can also smartly rewrite the code you have already written. This is Cursor's most proud "code editing" function. Whether it is a small modification or a large refactoring, this function can be very useful.
When performing code rewriting (or modification), Cursor's code modification suggestions will be presented in the form of a hint box, rather than the gray code hint for code completion.
Cursor Prediction
All the functions introduced above are based on Cursor's current cursor position, combined with the code context, to provide completion or modification hints.
Even further.
Cursor can also predict the position where you may edit next. This powerful function is called "Cursor Prediction". (It seems I know why Cursor is called Cursor now)
In the above example, we can see that when you modify the name of a function, Cursor predicts that the function name at the position of the red circle below should also change accordingly.
In the same example, when you change the name of the updates variable to updatesToServer, Cursor will predict that the updates variable below should also be updated to updatesToServer.
Tips
Tab in Peek
Cursor's Tab feature is not limited to the main editing window. It can also be used in the preview window of "Go to Definition" or "Go to Type Definition". This feature is particularly useful when adding new function parameters.
For example, when you need to modify a function definition and then quickly fix all places where the function is used, this function is very convenient. Especially for users who use vim, they can combine the gd
command, first modify the function definition, and then quickly fix all the call locations.
In the above example, we can see that the user uses the Tab feature in the preview window to modify the function definition and add a new parameter.
This function can improve the efficiency of code refactoring and make it easier and faster to add new features or modify existing interfaces.
Partial Accepts
You can accept the next word of the suggestion by pressing Ctrl/⌘
and the right arrow. This allows you to have more precise control over the code completion process.
Future Development of the Tab Feature
In terms of the usage experience, there is still room for improvement in the context reference of the Tab feature. For example, when returning to the current file after modifying code from another file, the error rate of the Tab feature's prompts is relatively high.
According to the future plans mentioned in Cursor's blog Next Action Prediction, the Tab feature will support cross-file code generation prompts in the future, not limited to generating code suggestions for the current file only. This means that Cursor will be able to better understand the context of the entire project and provide more accurate and useful code suggestions.
Summary
Generally speaking, Cursor's Tab feature is a powerful and intuitive AI-assisted programming tool. Through this tutorial, you should have a sufficient understanding of it.
However, Cursor's power is not as simple as it seems. After in-depth research, it is found that Cursor's team has done a lot of improvement and optimization work.
Cursor's Tab feature uses a self-developed model. Many methods of training the model and details of optimization are mentioned in Cursor's blog. Friends who are interested can take a look.