Using Slash Commands in GitHub Copilot for Visual Studio

Using Slash Commands in GitHub Copilot for Visual Studio

GitHub Copilot is a coding assistant powered by Artificial Intelligence (AI), which can run in various environments and help you be more efficient in your daily coding tasks. In this new series of content, we will show you how GitHub Copilot works in Visual Studio specifically and how it helps you being more productive.


In this installment, we will demonstrate the usage of Slash Commands. Like my colleague Bruno Capuano calls them in the new short video we just published, Slash Commands are like "little magic spells"; in other words, by typing a slash (/) in a GitHub Copilot prompt, you open a choice where you can choose some commands which will have a predefined action. 



Opening the Slash Commands menu

In order to open the Slash Commands menu, you can click on the Slash button inside the GitHub Copilot Chat window.




Another option is to simply type a slash character into the message box directly. Either action will open the menu which looks like this:




Let's review the commands together.

  • askvs: This command "asks Visual Studio" a question. You can use it to ask questions about your code, about some functionalities, etc.
  • doc: This command will insert a documentation comment related to the position of the cursor. For example, if the cursor is inside a method. GitHub Copilot will propose a comment for this method. 
  • exp: This command starts a new conversation thread, with a brand new context. You can then switch between the threads from a combo box on top of the chat window.
  • explain: This command will explain a portion of code, as we saw in previous videos. If code is selected inside the current code window, this code will be explained. You can also use the # command to specify a different context.
  • fix: This command will propose a fix for the code currently in context.
  • generate: This command will generate some code corresponding to the question you just asked.
  • help: This command will show some help about GitHub Copilot itself.
  • optimize: This command will analyze the code in context, and propose an optimization (in terms of performance, lines of code, etc).
  • tests: This command will create a unit test for the currently selected code. No more excuses for not writing tests!!

We will get more in details about each of these commands in future posts.


An example

In the short video, Bruno is showing how the /fix command works. There are a few typos and other issues in the selected code, and GitHub Copilot proposes a solution. As Bruno shows, the Slash Commands also work in the inline chat dialog which can be opened within any code file by typing Alt-Slash (Alt-/) or by right clicking and selecting "Ask Copilot" from the context menu.


More information

As always, you can find more information, in our collection with resources here. Also, you can see the full-length video here.


Stay tuned to this blog for more content posted regularly. And of course, you can also subscribe to our YouTube channel to get more video content!

Published on:

Learn more
Azure Developer Community Blog articles
Azure Developer Community Blog articles

Azure Developer Community Blog articles

Share post:

Related posts

Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy