Cheat Sheet Slides - Terminal, Vim & Git
This page is a work in progress. Please suggest changes!
TERMINAL
Terminal Navigation
cd <path>
Change directory to specified path
cd ..
Move up one directory level
cd -
Move to the last-visited directory
cd ~
Go to home directory
pwd
Print working directory (show current path)
TERMINAL
Terminal Navigation
ls
List directory contents
ls -al
List all files (including hidden) with details
cat <file>
Display file contents
less <file>
Display file contents, with paging for long files
Pro Tip:
Use
Tab
for auto-completion
TERMINAL
File Operations
mv <source> <dest>
Move or rename files/directories
cp <source> <dest>
Copy files/directories
rm <file>
Remove a file
rm -rf <folder>
Remove directory and all contents
mkdir <name>
Create a new directory
TERMINAL
Essential Terminal Commands
Ctrl+C
Cancel/interrupt current command
↑ / ↓ arrows
Navigate command history
clear
Clear terminal screen
VIM
File Operations
vim <file>
Open file in vim (from terminal)
:wq
Save and quit
:w
Save file without quitting
:q!
Quit without saving
:e <file>
Edit a new file
VIM
Movements
h
j
k
l
or
←
↓
↑
→
Left, Down, Up, Right
0 (zero)
Move to beginning of line
$
Move to end of line
w
Move to start of next word
e
Move to end of current word
gg
Go to first line of file
G
Go to last line of file
VIM
Repeat Commands
<#><command>
Repeat a command multiple times. Example:
5k
moves up 5 lines.
VIM
Mode Switching
i
Insert mode
i
Insert mode
A
Insert at line end
o
Insert to new line below
v
Visual mode
V
Visual mode (full lines)
Esc
Return to Normal Mode
Pro Tip:
Remap your
Caps Lock
key to
Esc
in Mac System Settings
VIM
Copy/Paste
y
Yank (copy) selection (from visual mode)
p
Paste after cursor
"ay
Yank to register a (you can substitute for any register name here).
"ap
Paste from register a
VIM
Shortcuts
x
Delete character under cursor
r
Replace character under cursor
VIM
Macros
qa
Start recording actions into register a
q
Stop recording
@a
Play back register a
Pro Tip:
Macros are just text in registers. Use :reg to inspect all registers
VIM
One-Line Shortcuts
yy
Yank (copy) current line
dd
Delete (cut) current line
gqq
Break current line into multiple lines.
VIM
Window Splits
:vsp
Vertical split
:sp
Horizontal split
Ctrl+w <h,j,k,l>
Move between splits
Ctrl+w < or >
Resize split width
Ctrl+w =
Equalize split sizes
VIM
Tabs
:tabnew
New Tab
:tabclose
Close current tab
:gt
Next Tab
:gT
Previous Tab
VIM
Vim Registers and Buffers
:reg
Show all registers
"+p
Paste from system clipboard
:ls
List all buffers
:b<number>
Switch to buffer number
GIT
Git Basic Workflow
git status
Check status of working directory
git add <file>
Stage file for commit
git add .
Stage all changes
git commit -m "message"
Commit staged changes with message
git push
Push commits to remote repository
git pull
Fetch and merge from remote
git clone <url>
Clone a repository
GIT
Git Branch Management
git branch
List all branches (current highlighted)
git checkout <branch>
Switch to branch
git checkout -b <branch>
Create and switch to new branch
git merge <branch>
Merge specified branch into current
git push -u origin <branch>
Push branch to remote and set upstream
GIT
Git Useful Commands
git log --oneline
Compact commit history
git diff
Show unstaged changes
git stash
Temporarily save changes
git stash pop
Re-apply stashed changes
git reset <file>
Unstage file
git fetch
Download objects without merging
Config Files
~/.bashrc or ~/.zshrc
Aliases, Path
~/.vimrc
Colors, line numbers
~/.gitconfig
User information, preferred tools
.git/config
Remote and branch configuration for each repo
~/.ssh
All of your SSH keys should live here