Introduction
GitHub Copilot is an AI assistant that helps you write code faster right inside Visual Studio. With just a few keystrokes, Copilot can generate code, add comments, fix errors, and even write unit tests for you.
One powerful feature in Visual Studio is the Copilot chat window, which you can open by pressing ALT + /. In this window, you can type your question in plain English or use special slash commands to ask Copilot to do specific tasks like /generate, /fix, or /doc.
In this article, we'll learn what these slash commands are and how they can make your coding easier and more productive.
In Visual Studio, ALT + / launches the CoPilot.

In this Window, you can type the Copilot command in plain English, or you can use slash commands. Slash commands are a shorter version to ask Copilot to generate content for you.
What are Copilot slash commands?
Slash commands are short cuts to give instructions to Copilot to create and review content.
You can see all slash commands by typing slash (/) in the Copilot window.

- /doc: Add a documentation comment.
- /explain: Explain the code.
- /fix: Propose a fix for problems in the selected code.
- /help: Get help on Copilot chat.
- /generate: Generate code to answer your question.
- /tests: Create unit tests for the selected code.
Slash commands explained
Let’s look at the slash command in more detail and how to use them.
/generate: Generate code to answer your question
Suppose you’re working on a Python project and need to read data from a CSV file. You can use the /generate command to get relevant code snippets. Here’s how,
Type a question or a description of what you want to achieve. For instance.
How do I read a CSV file in Python?
Add /generate followed by relevant keywords.
/generate read CSV file Python
Copilot will provide code snippets related to reading CSV files in Python. It also creates a new file with .py extension. The code generated by Copilot looks like this.
import csv
def read_csv_file(file_path):
data = []
with open(file_path, 'r') as file:
reader = csv.reader(file)
for row in reader:
data.append(row)
return data
# Example usage
file_path = "../../../../AppData/Local/Temp/2yzt2jkr.csv"
data = read_csv_file(file_path)
print(data)
/explain: Explain the selected code
You can use the /explain code which is like writing a documentation. You may wan to use the same command to write a detailed blog about your code.

Hit ENTER.
Copilot writes detailed explanation of the selected code.

Copilot also suggest the next steps you want to add in this code.

/doc: Add a documentation comment.
This command add comments the code.
Select the code above and type /doc command in the Copilot command window and Hit ENTER.

The Copilot adds the following comments to the selected code.
import csv
def read_csv_file(file_path):
"""
Read a CSV file and return the data as a list of rows.
Args:
file_path (str): The path to the CSV file.
Returns:
list: The data from the CSV file as a list of rows.
"""
data = []
with open(file_path, 'r') as file:
reader = csv.reader(file)
for row in reader:
data.append(row)
return data
# Example usage
file_path = "../../../../AppData/Local/Temp/2yzt2jkr.csv"
data = read_csv_file(file_path)
print(data)









Join the conversation! Your thoughts help the community grow.