Skip to content

Quick Reference Cheatsheets 📋

Tất cả shortcuts và commands quan trọng nhất ở một nơi.

VS Code Shortcuts

ShortcutActionUse Case
Ctrl + PQuick OpenOpen files instantly
Ctrl + Shift + PCommand PaletteAccess all commands
F12Go to DefinitionJump to source
Alt + Left/RightNavigate Back/ForwardReturn to previous location
Ctrl + GGo to LineJump to specific line
Ctrl + Shift + OGo to SymbolNavigate within file

Editing

ShortcutActionUse Case
Ctrl + DSelect Next OccurrenceMulti-cursor editing
Alt + ClickAdd CursorManual multi-cursor
Ctrl + Shift + LSelect All OccurrencesRename all instances
Alt + Up/DownMove LineReorder code
Shift + Alt + DownDuplicate LineCopy similar code
Ctrl + /Toggle CommentComment/uncomment
Ctrl + Shift + KDelete LineRemove line quickly

View Management

ShortcutActionUse Case
Ctrl + BToggle SidebarMore screen space
Ctrl + \Split EditorView 2 files
Ctrl + 1/2/3Focus Editor GroupSwitch between splits
Ctrl + WClose EditorClose current file
Ctrl + K, ZZen ModeDistraction-free coding
Ctrl + `Toggle TerminalQuick terminal access

Search & Replace

ShortcutActionUse Case
Ctrl + FFindSearch in file
Ctrl + HReplaceFind and replace
Ctrl + Shift + FFind in FilesSearch entire project
Ctrl + Shift + HReplace in FilesReplace across project
F3 / Shift + F3Find Next/PreviousNavigate search results

Code Folding

ShortcutActionUse Case
Ctrl + Shift + [Fold RegionCollapse code block
Ctrl + Shift + ]Unfold RegionExpand code block
Ctrl + K, Ctrl + 0Fold AllCollapse everything
Ctrl + K, Ctrl + JUnfold AllExpand everything

Git Commands

Basic Workflow

bash
# Check status
git status

# Stage changes
git add .                    # Stage all
git add file.txt             # Stage specific file

# Commit
git commit -m "message"      # Commit with message
git commit --amend           # Amend last commit

# Push/Pull
git push                     # Push to remote
git pull                     # Pull from remote
git fetch                    # Fetch without merge

Branching

bash
# Create branch
git branch feature-name      # Create branch
git checkout -b feature-name # Create and switch

# Switch branch
git checkout main            # Switch to main
git switch feature-name      # Modern syntax

# Merge
git merge feature-name       # Merge into current branch

# Delete branch
git branch -d feature-name   # Delete local branch
git push origin --delete feature-name  # Delete remote

History & Inspection

bash
# View history
git log                      # Full history
git log --oneline            # Compact view
git log --graph --all        # Visual graph

# View changes
git diff                     # Unstaged changes
git diff --staged            # Staged changes
git diff branch1..branch2    # Compare branches

# Show commit
git show <commit-hash>       # Show commit details

Undo Changes

bash
# Discard changes
git checkout -- file.txt     # Discard file changes
git restore file.txt         # Modern syntax

# Unstage
git reset HEAD file.txt      # Unstage file
git restore --staged file.txt # Modern syntax

# Undo commit
git reset --soft HEAD~1      # Keep changes staged
git reset --hard HEAD~1      # Discard changes (dangerous!)
git revert <commit-hash>     # Create new commit that undoes

Stash

bash
# Save work temporarily
git stash                    # Stash changes
git stash save "message"     # Stash with message
git stash list               # List stashes
git stash pop                # Apply and remove stash
git stash apply              # Apply without removing
git stash drop               # Delete stash

Terminal Commands

bash
# Change directory
cd /path/to/dir              # Absolute path
cd ..                        # Parent directory
cd ~                         # Home directory
cd -                         # Previous directory

# List files
ls                           # List files
ls -la                       # List all with details
ls -lh                       # Human-readable sizes

# Current directory
pwd                          # Print working directory

File Operations

bash
# Create
touch file.txt               # Create empty file
mkdir dirname                # Create directory
mkdir -p path/to/dir         # Create nested directories

# Copy/Move/Delete
cp source dest               # Copy file
cp -r source dest            # Copy directory
mv source dest               # Move/rename
rm file.txt                  # Delete file
rm -rf dirname               # Delete directory (careful!)

# View files
cat file.txt                 # Print entire file
less file.txt                # View with pagination
head -n 10 file.txt          # First 10 lines
tail -n 10 file.txt          # Last 10 lines
tail -f file.txt             # Follow file (live updates)
bash
# Find files
find . -name "*.js"          # Find by name
find . -type f -mtime -7     # Modified in last 7 days
fd "\.js$"                   # Modern alternative (faster)

# Search content
grep "pattern" file.txt      # Search in file
grep -r "pattern" .          # Recursive search
grep -i "pattern" file.txt   # Case insensitive
rg "pattern"                 # Modern alternative (faster)

Process Management

bash
# View processes
ps aux                       # All processes
ps aux | grep node           # Find specific process
top                          # Interactive process viewer
htop                         # Better top (if installed)

# Kill process
kill <PID>                   # Graceful kill
kill -9 <PID>                # Force kill
pkill node                   # Kill by name

Network

bash
# Check connectivity
ping google.com              # Test connection
curl https://api.example.com # Make HTTP request
wget https://example.com/file.zip # Download file

# Port usage
netstat -tuln                # List listening ports
lsof -i :3000                # What's using port 3000

Permissions

bash
# Change permissions
chmod +x script.sh           # Make executable
chmod 644 file.txt           # rw-r--r--
chmod 755 script.sh          # rwxr-xr-x

# Change owner
chown user:group file.txt    # Change owner and group
chown -R user:group dir/     # Recursive

Node.js / npm Commands

Package Management

bash
# Initialize project
npm init                     # Interactive setup
npm init -y                  # Skip questions

# Install packages
npm install                  # Install from package.json
npm install package-name     # Install package
npm install -D package-name  # Install as dev dependency
npm install -g package-name  # Install globally

# Update packages
npm update                   # Update all packages
npm update package-name      # Update specific package
npm outdated                 # Check for updates

# Remove packages
npm uninstall package-name   # Remove package
npm prune                    # Remove unused packages

Scripts

bash
# Run scripts
npm start                    # Run start script
npm test                     # Run tests
npm run build                # Run build script
npm run dev                  # Run dev script (custom)

# List scripts
npm run                      # List all available scripts

Troubleshooting

bash
# Clear cache
npm cache clean --force      # Clear npm cache

# Reinstall
rm -rf node_modules package-lock.json
npm install                  # Fresh install

# Check versions
node -v                      # Node version
npm -v                       # npm version

Docker Commands

Container Management

bash
# Run container
docker run image-name        # Run container
docker run -d image-name     # Run in background
docker run -p 8080:80 image  # Port mapping
docker run -v /host:/container image # Volume mount

# List containers
docker ps                    # Running containers
docker ps -a                 # All containers

# Stop/Start
docker stop container-id     # Stop container
docker start container-id    # Start container
docker restart container-id  # Restart container

# Remove
docker rm container-id       # Remove container
docker rm -f container-id    # Force remove

Image Management

bash
# List images
docker images                # List all images

# Build image
docker build -t name:tag .   # Build from Dockerfile

# Pull/Push
docker pull image-name       # Download image
docker push image-name       # Upload image

# Remove
docker rmi image-id          # Remove image
docker image prune           # Remove unused images

Cleanup

bash
# Remove all stopped containers
docker container prune

# Remove all unused images
docker image prune -a

# Remove all unused volumes
docker volume prune

# Remove everything
docker system prune -a

Keyboard Shortcuts by Platform

Windows/Linux

ActionShortcut
CopyCtrl + C
PasteCtrl + V
CutCtrl + X
UndoCtrl + Z
RedoCtrl + Y
Select AllCtrl + A
SaveCtrl + S
FindCtrl + F

macOS

ActionShortcut
CopyCmd + C
PasteCmd + V
CutCmd + X
UndoCmd + Z
RedoCmd + Shift + Z
Select AllCmd + A
SaveCmd + S
FindCmd + F

Regular Expressions Quick Reference

Basic Patterns

PatternMatchesExample
.Any charactera.c matches "abc", "a1c"
\dDigit (0-9)\d{3} matches "123"
\wWord character\w+ matches "hello"
\sWhitespace\s+ matches spaces
^Start of string^Hello matches "Hello world"
$End of stringworld$ matches "Hello world"

Quantifiers

PatternMeaningExample
*0 or morea* matches "", "a", "aa"
+1 or morea+ matches "a", "aa"
?0 or 1a? matches "", "a"
{n}Exactly na{3} matches "aaa"
{n,}n or morea{2,} matches "aa", "aaa"
{n,m}Between n and ma{2,4} matches "aa", "aaa", "aaaa"

Common Patterns

regex
# Email
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

# URL
^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b

# Phone (US)
^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$

# Date (YYYY-MM-DD)
^\d{4}-\d{2}-\d{2}$

# Hex Color
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$

HTTP Status Codes

Success (2xx)

CodeMeaning
200OK - Request succeeded
201Created - Resource created
204No Content - Success, no response body

Redirection (3xx)

CodeMeaning
301Moved Permanently
302Found (Temporary Redirect)
304Not Modified (Cached)

Client Errors (4xx)

CodeMeaning
400Bad Request - Invalid syntax
401Unauthorized - Authentication required
403Forbidden - No permission
404Not Found - Resource doesn't exist
422Unprocessable Entity - Validation failed
429Too Many Requests - Rate limited

Server Errors (5xx)

CodeMeaning
500Internal Server Error
502Bad Gateway - Invalid response from upstream
503Service Unavailable - Server overloaded
504Gateway Timeout - Upstream timeout

🎯 Luyện tập ngay