The one about accepting Tab suggestions in Cursor

In the previous post, I mentioned that I was starting to use Cursor as my main IDE, after having worked with VSCode and Copilot for a while.

A key advantage of Cursor for VSCode users is its support for the same keyboard shortcuts, allowing for a seamless transition:

Cursor's Quick Start

It allowed me to be really productive with this IDE almost immediately. And I say almost, because I ran into some issues when trying to accept AI suggestions on macOS.

Cursor allows you to autocomplete with Tab, the model they have trained in-house. With Tab, you can autocomplete multiple lines and blocks of code and jump in and across files to the next autocomplete suggestion.

As an example, I am going to show what happens when I try to accept a suggestion by adding a simple console.log to a JS file:

User cannot accept suggestions with tab key in Cursor

You can see that I can only accept a suggestion if I place the cursor over the suggestion itself and click Accept.

I dealt with this issue for longer than I would like to admit before I finally had time to investigate the root cause.

When I was able to look into the problem, I started with a quick Google search, where I did not find a real solution. Actually, that was a good sign, because it probably meant it was due to a misconfiguration on my end.

So, I continued by visually searching for the keyboard shortcuts associated with the tab key.

To do this, you have to go to the command palette (control + shift + p) and type keyboard shortcuts. There, you choose the option that does not specify JSON.

Then, you have to type "tab", with the quotes, or on the right side of the search bar, click Record Keys and press the tab key.

Cursor's Keyboard Shortcuts

The first detail you might note is that the source for almost all the commands is User. This is because I do not like working with macOS, but I have to for work, so I configured the system to be as similar as possible to my personal laptop with Linux. I have a post where I discussed this topic in more detail.

Another important detail to note is the first command associated with this key and its when clause context: cpp.shouldAcceptTab. We will need to use it pretty soon.

Next, we go back to the command palette and type keyboard shortcuts again. This time, we choose the option that specifies JSON.

Here we have to search for the commands associated with the tab key and disable them one by one until we find the one that is interfering with the expected behavior in Cursor. I started with the most obvious choice:

{
  "key": "tab",
  "command": "tab",
  "when": "editorTextFocus && !editorReadonly && !editorTabMovesFocus"
}

To test my theory, I commented out the entire entry for that shortcut:

Shortcut disabled in Cursor to validate default behavior

As expected, with that command disabled, I can now accept Tab's suggestions. However, I noticed an strange behavior when indenting code, for example.

Weird behavior found while trying to indent code with tab key in Cursor

So, I added the condition we saw earlier, negated, to this command's when clause:

{
  "key": "tab",
  "command": "tab",
  "when": "!cpp.shouldAcceptTab && editorTextFocus && !editorReadonly && !editorTabMovesFocus"
}

Now I can accept Tab's suggestions without interfering with the default behavior of the tab key.

Weird behavior found regarding indentation in the code with tab key in Cursor is now solved

Once again, there was one small detail that still was not working as I expected:

User not always can accept suggestions with tab key in Cursor

When I had a Tab suggestion and other suggestions from the current context, pressing the tab key accepted the first suggestion from the context, and only when I pressed the tab key again did it accept the expected suggestion.

To find the command that was interfering with this behavior, I disabled them one by one until I found the one:

{
  "key": "tab",
  "command": "acceptSelectedSuggestion",
  "when": "suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus"
}

Remember to re-enable each command after you have confirmed it is not the one you were looking for.

I added the same negated condition to this when clause:

{
  "key": "tab",
  "command": "acceptSelectedSuggestion",
  "when": "!cpp.shouldAcceptTab && suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus"
}

The result is now exactly what I expected:

User can accept suggestions with tab key in Cursor

In this case, the standard behavior of the tab key was clashing with Cursor's AI suggestion feature. The solution was to only trigger the default tab and acceptSelectedSuggestion commands when the AI does not have a suggestion ready.

The key takeaway is not just about this specific fix, but about the power of when clauses for fine-tuning the IDE to behave exactly how you want it to. Hopefully, this guide saves you some time and helps you get back to coding faster.

Thank you for reading and see you in the next one!


0
Subscribe to my newsletter

Read articles from David Montesdeoca directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

David Montesdeoca
David Montesdeoca

I love learning new stuff, especially when it comes to building software. I'm really interested in software architecture, clean code, testing and best practices.