Setup VS Code và GitHub Copilot
1. Cài đặt VS Code
Bước 1: Download VS Code
Truy cập code.visualstudio.com và download phiên bản phù hợp với hệ điều hành của bạn.
Bước 2: Cài đặt
- Windows: Chạy file
.exevà follow wizard - macOS: Mở file
.dmg, kéo VS Code vào Applications - Linux: Sử dụng package manager hoặc
.deb/.rpm
Bước 3: Verify installation
Bash
1code --version2# Output: 1.85.0 (hoặc phiên bản mới hơn)2. Đăng ký GitHub Copilot
Option 1: Free Trial (30 ngày)
- Truy cập github.com/features/copilot
- Click "Start my free trial"
- Đăng nhập GitHub account
- Nhập thông tin thanh toán (sẽ không bị charge trong 30 ngày)
Option 2: Student/Teacher (FREE)
Nếu bạn là student hoặc teacher:
- Truy cập education.github.com
- Apply cho GitHub Student Developer Pack
- Verify với email
.eduhoặc giấy tờ - Nhận GitHub Copilot miễn phí!
Option 3: Subscription
- Individual: 100/năm
- Business: $19/user/tháng
- Enterprise: Custom pricing
3. Cài đặt GitHub Copilot Extension
Trong VS Code
- Mở VS Code
- Nhấn
Ctrl+Shift+X(Windows/Linux) hoặcCmd+Shift+X(macOS) - Tìm kiếm "GitHub Copilot"
- Click Install cho extension chính thức từ GitHub
Extensions cần cài
| Extension | Mô tả |
|---|---|
| GitHub Copilot | Core autocomplete |
| GitHub Copilot Chat | Chat interface |
Đăng nhập
- Sau khi install, VS Code sẽ prompt đăng nhập
- Click "Sign in to GitHub"
- Authorize trong browser
- Quay lại VS Code
4. Verify Copilot hoạt động
Test 1: Autocomplete
Tạo file test.py và gõ:
Python
1# Function to calculate fibonacci2def fibCopilot sẽ suggest toàn bộ function. Nhấn Tab để accept.
Test 2: Comment-driven
Python
1# Create a function that takes a list of numbers 2# and returns the sum of all even numbersĐợi một chút, Copilot sẽ sinh code!
Test 3: Copilot Chat
- Nhấn
Ctrl+Shift+Iđể mở Copilot Chat - Gõ: "Explain what this code does"
- Paste code bất kỳ
5. Cấu hình Copilot Settings
Mở Settings
Ctrl+,(Windows/Linux) hoặcCmd+,(macOS)- Tìm "Copilot"
Recommended Settings
JSON
1{2 // Bật inline suggestions3 "editor.inlineSuggest.enabled": true,4 5 // Tự động show suggestions6 "github.copilot.enable": {7 "*": true,8 "plaintext": false,9 "markdown": true,10 "yaml": true11 },12 13 // Hiển thị panel14 "github.copilot.editor.enableAutoCompletions": true,15 16 // Chat settings17 "github.copilot.chat.localeOverride": "vi"18}Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Tab | Accept suggestion |
Esc | Dismiss suggestion |
Alt+] | Next suggestion |
Alt+[ | Previous suggestion |
Ctrl+Enter | Open Copilot panel |
Ctrl+Shift+I | Open Copilot Chat |
6. VS Code Extensions hữu ích khác
Kết hợp với Copilot, các extensions sau sẽ boost productivity:
Cho Python
- Python - Microsoft's Python extension
- Pylance - Fast IntelliSense
- Black Formatter - Code formatting
Cho JavaScript/TypeScript
- ESLint - Linting
- Prettier - Formatting
- Auto Import - Tự động import
General
- GitLens - Git superpowers
- Error Lens - Inline error display
- Material Icon Theme - Beautiful icons
7. Troubleshooting
Copilot không suggest
- Check subscription status tại GitHub Settings
- Đảm bảo đã sign in VS Code
- Restart VS Code
- Check network/firewall
Suggestions chậm
- Check internet connection
- Thử disconnect VPN
- Có thể server đang busy
Error "Copilot could not connect"
Bash
1# Windows2ipconfig /flushdns3 4# macOS/Linux5sudo killall -HUP mDNSResponder8. Exercise: First Vibe Coding
Hãy thử tạo một chương trình đơn giản hoàn toàn bằng Vibe Coding:
Yêu cầu
Tạo file calculator.py với các tính năng:
- Cộng, trừ, nhân, chia
- Menu để user chọn operation
- Loop cho đến khi user quit
Cách làm
- Tạo file mới
calculator.py - Viết comment mô tả yêu cầu
- Để Copilot sinh code
- Review và adjust nếu cần
Hint
Python
1# Simple calculator program2# Features:3# - Add, subtract, multiply, divide two numbers4# - Show menu for user to select operation5# - Continue until user chooses to quit6# - Handle division by zero errorĐợi Copilot sinh code và so sánh với solution bên dưới!
💡 Click để xem solution
Python
1def add(a, b):2 return a + b34def subtract(a, b):5 return a - b67def multiply(a, b):8 return a * b910def divide(a, b):11 if b == 0:12 return "Error: Division by zero"13 return a / b1415def calculator():16 while True:17 print("\n--- Simple Calculator ---")18 print("1. Add")19 print("2. Subtract")20 print("3. Multiply")21 print("4. Divide")22 print("5. Quit")23 24 choice = input("Choose operation (1-5): ")25 26 if choice == '5':27 print("Goodbye!")28 break29 30 if choice in ['1', '2', '3', '4']:31 num1 = float(input("Enter first number: "))32 num2 = float(input("Enter second number: "))33 34 if choice == '1':35 print(f"Result: {add(num1, num2)}")36 elif choice == '2':37 print(f"Result: {subtract(num1, num2)}")38 elif choice == '3':39 print(f"Result: {multiply(num1, num2)}")40 elif choice == '4':41 print(f"Result: {divide(num1, num2)}")42 else:43 print("Invalid choice!")4445if __name__ == "__main__":46 calculator()Tiếp theo
Ở bài tiếp theo, chúng ta sẽ học cách sử dụng Copilot Autocomplete hiệu quả - các tips và tricks để maximize productivity!
