How to fix the shortcut error when using Github Copilot on VSCode

January 12, 2022 MrAnyx 3 min de lecture

If you are reading this post, you have probably already heard of Github Copilot. You are maybe already using it in a personal project or a professional project.

To briefly explain what is Github Copilot, it is a tool that, as its name says, help you write code. It works thanks to artificial intelligence and machine learning and it is based on OpenAI.

How does it work ?

In practice, it is a tool that help you to write code by showing suggestions. It is based on the idea that you can write code in a more efficient way by using the same code that you have written before. In other words, Github Copilot analizes your code of your entire project and creates suggestions to automatically create new code.

For instance, you can write a comment like this :

// Write a function that takes a string and returns a new string with all vowels removed.

and Github Copilot will display a suggestion like this :

function disemvowel(str) {
  return str.replace(/[aeiou]/gi, '');
}

Without even looking at the code, Github Copilot will suggest you some functions that you can use to write your code.

If you want more information about Github Copilot, you can visit its website.

Shortcuts issue

If you are reading this, you are probably looking for a solution to solve the issue of Github Copilot not working on your project when you are using the shortcut to autocomplete a suggestion.

This issue happen when you press the tab key and nothing happens. This isbecause there is conflict between the tab key for autocompletion and the tab key for indentation.

Solve this issue

To solve this issue, you need to update the VSCode shortcuts. To do so you need to open the settings of VSCode and go to the Keyboard section (or press Ctrl+k and then Ctrl+s).

Then, in the search bar, type editor.action.inlineSuggest.commit. You should see the corresponding shortcut.

Then, in the Keybinding section, double-click on the previous shortcut, press the Tab key twice and then press Enter to validate.

Now, if you want to autocomplete a suggestion, you can press the Tab key twice instead of once. Simple Tab will still work and if you are using the Emmet extension, you can still use a single Tab to autocomplete Emmet suggestions.

Conclusion

Github Copilot is a great tool that help you to write code faster. But it is still a very young tool and it is still in development and sometimes it doesn't work as expected, especially on VSCode.

But it is a great tool and it is very easy to use. And with this post, you should be able to use it properly with all its features.

Cover by Pixabay


Cette œuvre est mise à disposition selon les termes de la licence Licence Creative Commons