Copilot Chat (accessible inline via Ctrl+I / Cmd+I or in the dedicated Chat view via Ctrl+Alt+I / Cmd+Alt+I) allows for powerful, conversational interactions to perform various coding tasks.
Get better results by:
#selection
for selected code, #file
for the active file, #file:myFile.js
for a specific file.@workspace
(VS Code) or @project
(JetBrains) to reference the broader project context.Generate code directly within the chat.
Example Prompt:
Generate a C# method to calculate the SHA256 hash of a string input.
You can then copy, insert, or preview the generated code using the buttons provided in the chat response.
Understand code faster.
/explain
slash command, or type a prompt like:/explain
Or:
Explain the purpose of the code in #selection
Get help fixing errors or finding potential issues.
/fix
slash command or ask specific questions:/fix the errors in #selection
Why is this code throwing a NullPointerException? #selection
Suggest improvements to make #selection more robust against errors.
Add comments or docstrings.
/doc
slash command or prompt:/doc
Add XML documentation comments to the selected C# method.
Generate test cases for selected code.
/tests
slash command:/tests
Copilot will attempt to generate relevant unit tests using common frameworks for the language.
Copilot Chat can attempt to translate code between languages.
Translate #selection from Python to C#.
AI code translation is often imperfect. Always thoroughly review translated code for logical errors, syntax issues, and language-specific best practices. It's a starting point, not a final solution.