Aggregation of some cheatsheets I use on a daily basis
Configure user information for all local repositories
$ git config --global user.name "[name]"
Sets the name you want attached to your commit transactions
$ git config --global user.email "[email address]"
Sets the email you want attached to your commit transactions
$ git config --global color.ui auto
Enables helpful colorization of command line output
Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to. Use git status to see which branch that is.
$ git branch [branch-name]
Creates a new branch
$ git checkout [branch-name]
Switches to the specified branch and updates the working directory
$ git merge [branch]
Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation.
$ git branch -d [branch-name]
Deletes the specified branch
When starting out with a new repository, you only need to do it once; either locally, then push to GitHub, or by cloning an existing repository.
$ git init
After using the git init command, link the local repository to an empty GitHub repository using the following command:
$ git remote add origin [url]
Turn an existing directory into a Git repository
$ git clone [url]
Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits
The .gitignore file Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore. You can find helpful templates for .gitignore files at github.com/github/gitignore.
Synchronize your local repository with the remote repository on GitHub.com
$ git fetch
Downloads all history from the remote tracking branches
$ git merge
Combines remote tracking branches into current local branch
$ git push
Uploads all local branch commits to GitHub
$ git pull
Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull is a combination of git fetch and git merge
Browse and inspect the evolution of project files
$ git log
Lists version history for the current branch
$ git log --follow [file]
Lists version history for a file, including renames
$ git diff [first-branch]...[second-branch]
Shows content differences between two branches
$ git show [commit]
Outputs metadata and content changes of the specified commit
$ git add [file]
Snapshots the file in preparation for versioning
$ git commit -m "[descriptive message]"
Records file snapshots permanently in version history
Erase mistakes and craft replacement history
$ git reset [commit]
Undoes all commits after [commit], preserving changes locally
$ git reset --hard [commit]
Discards all history and changes back to the specified commit
General Vim Tips: http://zzapper.co.uk/vimtips.html
Shortcut | Description |
---|---|
:qa |
Close all files |
:qa! |
Close all files, abandon changes |
--- | --- |
:w |
Save |
:wq / :x |
Save and close file |
--- | --- |
:q |
Close file |
:q! |
Close file, abandon changes |
--- | --- |
ZZ |
Save and quit |
ZQ |
Quit without checking changes |
Shortcut | Description |
---|---|
h j k l |
Arrow keys |
<C-U> / <C-D> |
Half-page up/down |
<C-B> / <C-F> |
Page up/down |
Shortcut | Description |
---|---|
b / w |
Previous/next word |
ge / e |
Previous/next end of word |
Shortcut | Description |
---|---|
0 (zero) |
Start of line |
^ |
Start of line (after whitespace) |
$ |
End of line |
| fc
| Go forward to character c
|
| Fc
| Go backward to character c
|
Shortcut | Description |
---|---|
gg |
First line |
G |
Last line |
:n |
Go to line n |
nG |
Go to line n |
Shortcut | Description |
---|---|
zz |
Center this line |
zt |
Top this line |
zb |
Bottom this line |
H |
Move to top of screen |
M |
Move to middle of screen |
L |
Move to bottom of screen |
Shortcut | Description |
---|---|
n |
Next matching search pattern |
N |
Previous match |
* |
Next whole word under cursor |
# |
Previous whole word under cursor |
Shortcut | Description |
---|---|
:tabedit [file] |
Edit file in a new tab |
:tabfind [file] |
Open file if exists in new tab |
:tabclose |
Close current tab |
:tabs |
List all tabs |
:tabfirst |
Go to first tab |
:tablast |
Go to last tab |
:tabn |
Go to next tab |
:tabp |
Go to previous tab |
Shortcut | Description |
---|---|
a |
Append |
A |
Append from end of line |
i |
Insert |
o |
Next line |
O |
Previous line |
--- | --- |
s |
Delete char and insert |
S |
Delete line and insert |
C |
Delete until end of line and insert |
--- | --- |
r |
Replace one character |
R |
Enter Replace mode |
--- | --- |
u |
Undo changes |
<C-R> |
Redo changes |
Shortcut | Description |
---|---|
Esc / <C-[> |
Exit insert mode |
<C-C> |
Exit insert mode, and abort current command |
Shortcut | Description |
---|---|
x |
Delete character |
--- | --- |
dd |
Delete line (Cut) |
yy |
Yank line (Copy) |
--- | --- |
p |
Paste |
P |
Paste before |
--- | --- |
"*p / "+p |
Paste from system clipboard |
"*y / "+y |
Paste to system clipboard |
Shortcut | Description |
---|---|
v |
Enter visual mode |
V |
Enter visual line mode |
<C-V> |
Enter visual block mode |
Shortcut | Description |
---|---|
d / x |
Delete selection |
s |
Replace selection |
y |
Yank selection (Copy) |
{: .-shortcuts} |
See Operators for other things you can do.
Operators let you operate in a range of text (defined by motion). These are performed in normal mode. {: .-setup}
| d
| w
|
| Operator | Motion |
Shortcut | Description |
---|---|
d |
Delete |
y |
Yank (copy) |
c |
Change (delete then insert) |
--- | --- |
> |
Indent right |
< |
Indent left |
= |
Autoindent |
--- | --- |
g~ |
Swap case |
gU |
Uppercase |
gu |
Lowercase |
--- | --- |
! |
Filter through external program |
See :help operator
Combine operators with motions to use them.
Shortcut | Description |
---|---|
d d |
(repeat the letter) Delete current line |
d w |
Delete to next word |
d b |
Delete to beginning of word |
2dd |
Delete 2 lines |
d ip |
Delete a text object (inside paragraph) |
(in visual mode) d |
Delete selection |
See: :help motion.txt
Text objects let you operate (with an operator) in or around text blocks (objects). {: .-setup}
| v
| i
| p
|
| Operator | [i]nside or [a]round | Text object |
{: .-css-breakdown}
Shortcut | Description |
---|---|
p |
Paragraph |
w |
Word |
s |
Sentence |
--- | --- |
[ ( { < |
A [], (), or {} block |
' " ` |
A quoted string |
--- | --- |
b |
A block [( |
B |
A block in [{ |
t |
A XML tag block |
{: .-shortcuts} |
Shortcut | Description |
---|---|
vip |
Select paragraph |
vipipipip |
Select more |
--- | --- |
yip |
Yank inner paragraph |
yap |
Yank paragraph (including newline) |
--- | --- |
dip |
Delete inner paragraph |
cip |
Change inner paragraph |
See Operators for other things you can do.
Shortcut | Description |
---|---|
gvimdiff file1 file2 [file3] |
See differences between files, in HMI |
Shortcut | Description |
---|---|
zo / zO |
Open |
zc / zC |
Close |
za / zA |
Toggle |
--- | --- |
zv |
Open folds for this line |
--- | --- |
zM |
Close all |
zR |
Open all |
--- | --- |
zm |
Fold more (foldlevel += 1) |
zr |
Fold less (foldlevel -= 1) |
--- | --- |
zx |
Update folds |
Uppercase ones are recursive (eg, zO
is open recursively).
Shortcut | Description |
---|---|
% |
Nearest/matching {[()]} |
[( [{ [< |
Previous ( or { or < |
]) |
Next |
--- | --- |
[m |
Previous method start |
[M |
Previous method end |
Shortcut | Description |
---|---|
<C-O> |
Go back to previous location |
<C-I> |
Go forward |
--- | --- |
gf |
Go to file in cursor |
Shortcut | Description |
---|---|
<C-A> |
Increment number |
<C-X> |
Decrement |
| z{height}<Cr>
| Resize pane to {height}
lines tall |
Shortcut | Description |
---|---|
:tag Classname |
Jump to first definition of Classname |
--- | --- |
<C-]> |
Jump to definition |
g] |
See all definitions |
<C-T> |
Go back to last tag |
<C-O> <C-I> |
Back/forward |
--- | --- |
:tselect Classname |
Find definitions of Classname |
:tjump Classname |
Find definitions of Classname (auto-select 1st) |
{: .-shortcuts} |
Shortcut | Description |
---|---|
~ |
Toggle case (Case => cASE) |
gU |
Uppercase |
gu |
Lowercase |
--- | --- |
gUU |
Uppercase current line (also gUgU ) |
guu |
Lowercase current line (also gugu ) |
{: .-shortcuts} |
Do these in visual or normal mode.
Shortcut | Description |
---|---|
`^ |
Last position of cursor in insert mode |
`. |
Last change in current buffer |
`" |
Last exited current buffer |
`0 |
In last file edited |
'' |
Back to line in current buffer where jumped from |
`` |
Back to position in current buffer where jumped from |
`[ |
To beginning of previously changed or yanked text |
`] |
To end of previously changed or yanked text |
`< |
To beginning of last visual selection |
`> |
To end of last visual selection |
--- | --- |
ma |
Mark this cursor position as a |
`a |
Jump to the cursor position a |
'a |
Jump to the beginning of the line with position a |
d'a |
Delete from current line to line of mark a |
d`a |
Delete from current position to position of mark a |
c'a |
Change text from current line to line of a |
y`a |
Yank text from current position to position of a |
--- | --- |
:marks |
List all current marks |
:delm a |
Delete mark a |
:delm a-d |
Delete marks a , b , c , d |
:delm abc |
Delete marks a , b , c |
Shortcut | Description |
---|---|
. |
Repeat last command |
]p |
Paste under the current indentation level |
--- | --- |
:set ff=unix |
Convert Windows line endings to Unix line endings |
Shortcut | Description |
---|---|
<C-R><C-W> |
Insert current word into the command line |
<C-R>" |
Paste from " register |
<C-X><C-F> |
Auto-completion of path in insert mode |
:center [width]
:right [width]
:left
See :help formatting
Shortcut | Description |
---|---|
<C-R>=128/2 |
Shows the result of the division : '64' |
Do this in insert mode.
:cq
:cquit
Works like :qa
, but throws an error. Great for aborting Git commands.
Shortcut | Description |
---|---|
:set spell spelllang=en_us |
Turn on US English spell checking |
]s |
Move to next misspelled word after the cursor |
[s |
Move to previous misspelled word before the cursor |
z= |
Suggest spellings for the word under/after the cursor |
zg |
Add word to spell list |
zw |
Mark word as bad/mispelling |
zu / C-X (Insert Mode) |
Suggest words for bad word under cursor from spellfile |
{: .-shortcuts} |
See :help spell
start new:
tmux
start new with session name:
tmux new -s myname
attach:
tmux a # (or at, or attach)
attach to named:
tmux a -t myname
list sessions:
tmux ls
tmux kill-session -t myname
tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill
In tmux, hit the prefix ctrl+b
(my modified prefix is ctrl+a) and then:
to see all the shortcuts keys in tmux simply use the bind-key ?
in my case that would be CTRL-B ?
:new<CR> new session
s list sessions
$ name session
c create window
w list windows
n next window
p previous window
f find window
, name window
& kill window
% vertical split
" horizontal split
o swap panes
q show pane numbers
x kill pane
+ break pane into window (e.g. to select text by mouse to copy)
- restore pane from window
⍽ space - toggle between layouts
<prefix> q (Show pane numbers, when the numbers show up type the key to goto that pane)
<prefix> { (Move the current pane left)
<prefix> } (Move the current pane right)
<prefix> z toggle pane zoom
You can do this by switching to the appropriate window, typing your Tmux prefix (commonly Ctrl-B or Ctrl-A) and then a colon to bring up a Tmux command line, and typing:
:setw synchronize-panes
You can optionally add on or off to specify which state you want; otherwise the option is simply toggled. This option is specific to one window, so it won’t change the way your other sessions or windows operate. When you’re done, toggle it off again by repeating the command. tip source
You can also resize panes if you don’t like the layout defaults. I personally rarely need to do this, though it’s handy to know how. Here is the basic syntax to resize panes:
PREFIX : resize-pane -D (Resizes the current pane down)
PREFIX : resize-pane -U (Resizes the current pane upward)
PREFIX : resize-pane -L (Resizes the current pane left)
PREFIX : resize-pane -R (Resizes the current pane right)
PREFIX : resize-pane -D 20 (Resizes the current pane down by 20 cells)
PREFIX : resize-pane -U 20 (Resizes the current pane upward by 20 cells)
PREFIX : resize-pane -L 20 (Resizes the current pane left by 20 cells)
PREFIX : resize-pane -R 20 (Resizes the current pane right by 20 cells)
PREFIX : resize-pane -t 2 20 (Resizes the pane with the id of 2 down by 20 cells)
PREFIX : resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)
Pressing PREFIX [ places us in Copy mode. We can then use our movement keys to move our cursor around the screen. By default, the arrow keys work. we set our configuration file to use Vim keys for moving between windows and resizing panes so we wouldn’t have to take our hands off the home row. tmux has a vi mode for working with the buffer as well. To enable it, add this line to .tmux.conf:
setw -g mode-keys vi
With this option set, we can use h, j, k, and l to move around our buffer.
To get out of Copy mode, we just press the ENTER key. Moving around one character at a time isn’t very efficient. Since we enabled vi mode, we can also use some other visible shortcuts to move around the buffer.
For example, we can use "w" to jump to the next word and "b" to jump back one word. And we can use "f", followed by any character, to jump to that character on the same line, and "F" to jump backwards on the line.
Function vi emacs
Back to indentation ^ M-m
Clear selection Escape C-g
Copy selection Enter M-w
Cursor down j Down
Cursor left h Left
Cursor right l Right
Cursor to bottom line L
Cursor to middle line M M-r
Cursor to top line H M-R
Cursor up k Up
Delete entire line d C-u
Delete to end of line D C-k
End of line $ C-e
Goto line : g
Half page down C-d M-Down
Half page up C-u M-Up
Next page C-f Page down
Next word w M-f
Paste buffer p C-y
Previous page C-b Page up
Previous word b M-b
Quit mode q Escape
Scroll down C-Down or J C-Down
Scroll up C-Up or K C-Up
Search again n n
Search backward ? C-r
Search forward / C-s
Start of line 0 C-a
Start selection Space C-Space
Transpose chars C-t
d detach
t big clock
? list shortcuts
: prompt
# Mouse support - set to on if you want to use the mouse
* setw -g mode-mouse off
* set -g mouse-select-pane off
* set -g mouse-resize-pane off
* set -g mouse-select-window off
# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"
# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on
# Center the window list
set -g status-justify centre
# Maximize and restore a pane
unbind Up bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp