Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Developer Cheat Sheets for bash, git, gpg, irssi, mutt, tmux, and vim. See my dotfiles repository for extra info.

Moved to https://github.com/JoshuaEstes/CheatSheets

Developer Cheat Sheets

This are my cheat sheets that I have compiled over the years. Tired of searching Google for the same things, I started adding the information here. As time went on, this list has grown. I use this almost everyday and this Gist is the first bookmark on my list for quick and easy access.

I recommend that you compile your own list of cheat sheets as typing out the commands has been super helpful in allowing me to retain the information longer.

NOTE: I have this page as my first bookmark in my address bar so that I am able to easily come back here. I edit this page often and when I find gems of knowledge, I will often place them in here.

Table of Contents

Bash

Moving

command description
ctrl + a Goto BEGINNING of command line
ctrl + e Goto END of command line
ctrl + b move back one character
ctrl + f move forward one character
alt + f move cursor FORWARD one word
alt + b move cursor BACK one word

Other

command description
ctrl + d Delete the character under the cursor
ctrl + l Clear the screen (same as clear command)
ctrl + p Fetch the previous command from the history list, moving back in the list (same as up arrow)
ctrl + n Fetch the next command from the history list, moving forward in the list (same as down arrow)
ctrl + u Clear all BEFORE cursor
ctrl + k Clear all AFTER cursor
ctrl + r Search backward starting at the current line and moving 'up' through the history as necessary
crtl + s Search forward starting at the current line and moving 'down' through the history as necessary
ctrl + c kill whatever is running
ctrl + d Exit shell (same as exit command)
ctrl + w delete the word BEFORE the cursor
ctrl + t swap the last two characters before the cursor
ctrl + y paste (if you used a previous command to delete)
ctrl + z Place current process in background
ctrl + _ undo
esc + t Swap last two words before the cursor
esc + .
esc + _
alt + [Backspace] delete PREVIOUS word
alt + < Move to the first line in the history
alt + > Move to the end of the input history, i.e., the line currently being entered
alt + ?
alt + *
alt + . print the LAST ARGUMENT (ie "vim file1.txt file2.txt" will yield "file2.txt")
alt + c
alt + d
alt + l
alt + n
alt + p
alt + r
alt + t
alt + u
~[TAB][TAB] List all users
$[TAB][TAB] List all system variables
@[TAB][TAB] List all entries in your /etc/hosts file
[TAB] Auto complete
!! Run PREVIOUS command (ie sudo !!)
!vi Run PREVIOUS command that BEGINS with vi
cd - change to PREVIOUS working directory

Kill a job

n = job number, to list jobs, run jobs

kill %n

Example:

kill %1

References

  1. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html

Git

Subtree Example

Add sub-project as remote

git remote add -f RemoteName RemoteUrl

Run git subtree command

git subtree add --prefix Path/To/Put/Code NameOfRemote master --squash

Pull subtree as needed

git fetch NameOfRemote master
git subtree pull --prefix Path/To/Put/Code NameOfRemote master --squash

Reference

Create a branch without a parent

Very useful when you are updating a project that you are rewriting. For example, say you are using semantic versioning and are wanting to start a new major version.

git checkout --orphan BRANCH

Delete All Branches that have been merged

Great for cleaning up local branches that aren't being used any more.

git checkout master
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

Ignore changes to a file that is being tracked

Ignore

git update-index --assume-unchanged [directory|file]

Unignore

git update-index --no-assume-unchanged [directory|file]

How to ignore dirty submodules

Edit your .git/config and add ignore = dirty.

[submodule "path/to/submodule"]
    path = path/to/submodule
    url = git://github.com/username/repo.git
    ignore = dirty

Clone a repo and give name other than origin

git clone -o upstream https://repo.git

Ignore Files for Repository without using .gitignore

Add the file .git/info/exclude and fill it with the contents you want to ignore. This will ONLY apply to the repository and will not be tracked by git.

Squash Commits

git log

Count the number of commits that you have made, let's say the previous 5 are your commits.

git rebase -i HEAD~5

The first commit leave as pick the rest will need to be changed to squash. After that you will be able to leave a new commit message or just leave as is to keep the commit messages from all previous commits.

Search for a specific line of code/file in the history

git log -S[search term]

Example:

git log -SThatOneFile.php

Copy file from one branch to current branch

Copy a file from branch and put into staging.

git checkout BRANCH path/to/file.ext

# Real Life Examples
git checkout origin/featureBranch web/js/random.js
# Pulls into your current branch web/js/random.js from
# origin/featureBranch

Git Grepping for fun and profit!

# Basic grep (case sensitive)
$ git grep 'search term'

# Case Insensitive search
$ git grep -i 'search term'

# Search within a directory
$ git grep 'search term' src/

# Search only files with `php` extension
$ git grep 'search term' -- '*.php'

# Grep in the 'src/` directory, only yml files
$ git grep 'search term' -- 'src/**.yml'

GnuPG

Listing Key Pairs

gpg --list-keys

For listing keys with the fingerprint, run

gpg --fingerprint

Generate New Key Pair

gpg --gen-key

Encrypt a message on command line

echo "Put message here" | gpg --armor --encrypt --recipient Joshua > FILE.gpg

This will put the encrypted text into FILE.gpg which you can send to someone or keep for later use. For decrypting the message, see the next section.

Decrypt a message from the command line

cat FILE.gpg | gpg

Displays the decrypted text on the command line.

Only display user X's key information

gpg --fingerprint Joshua

Signing Messages

echo "This is a top secret message" | gpg --clearsign

Signing Text Files

gpg --clearsign example.txt

This will create example.txt.asc file.

Verify Signatures

gpg --verifiy example.txt.asc

irssi

M = Meta Key, meta key is either the left alt or esc key.

command description
M + p Scroll up in window
M + n Scroll down in window
ctrl + p Previous window
ctrl + n Next window

JIRA

Find by Mentions of current user within the past 7 days

comment ~ currentUser() AND updatedDate >= -7d

Mutt

General

These key bindings will work on almost any menu you are in.

command description
* Move to last entry
= Move to first entry
: Enter muttrc command
> Scroll down one line
< Scroll up one line
[ Scroll up half a page
] Scroll down half a page
? Help
; Apply next function to tagged messages only
! Invoke command in subshell
return Select the current entry
esc + / Search up
/ Search down
H Move to top of page
j Move to next entry
k Move to previous entry
ctrl + l Redraw screen
L Move to bottom of page
M Move to middle of page
n Move to next match of search
q Exit menu
t Tag current entry
z Move to next page
Z Move to previous page

Index Menu

When you first open mutt you are in the index menu.

command description
& Link tagged message to current one
# Break the thread in two
% Toggle whether mailbox will be rewritten
. List mailboxes with new mail
$ Save changes to mailbox
@ Display full address of sender
esc + tab Jump to previous new or unread message
return Display message
tab Jump to next new or unread message
a Create alias from message sender
b Remail message to another user
esc + c Open a different folder (Read Only)
c Open a different folder
esc + C Make text/plain copy
C Copy message to another file/mailbox
esc + d Delete all messages in subthread
d Delete current message
ctrl + D Delete all messages in thread
D Delete messages matching a pattern
esc + e Use the current message as a template for a new one
e Edit the raw message
ctrl + E Edit attachment content type
f Forward message with comments
ctrl + F Wipe passphrase from memory
F Toggle the important flag for message
g Reply to all
G Retrive mail from POP server
h Display message and toggle header weeding
j Move to next undeleted message
esc + k Mail a PGP key
k Move to previous undeleted message
ctrl + K Extract supported public keys
esc + l Show current limit pattern
l Only show messages matching a pattern
L Reply to specific mailing list
m Compose new message
esc + n Jump to next subthread
ctrl + N Jump to next thread
N Toggle new flag
o Sort messages
O Sort messages in reverse order
Q Query external program for addresses
q Save changes to mailbox and quit
r Reply to message
ctrl + P Jump to previous thread
esc + p Jump to previous subthread
p Print current message
esc + P Check for classic PGP
P Jump to parent message in thread
ctrl + R Mark current thread as read
R Recall a postponed message
esc + r Mark current subthread as read
esc + s Save text/plain copy and delete
s Save message/attachment to mailbox/file
esc + t Tag current thread
ctrl + T Untag messages matching a pattern
T Tag messages matching pattern
esc + u Undelete all messages in subthread
u Undelete current entry
ctrl + U Undelete all messages in thread
U Undelete messages matching pattern
esc + v Collapse/uncollapse current thread
v Show mime attachments
esc + V Collapse/uncollapse all threads
V Show mutt version number and date
w Set a status flag
W Clear status flags from message

Pager Menu

command description
#
a
b
c
esc + c
C
esc + C
d
ctrl + D
esc + d
w
W
e
ctrl + E
f
F
g
h
j
J
k
K
&
L
ctrl + L
m
n
N
ctrl + N
esc + n
o
O
p
ctrl + P
esc + p
Q
q
r
R
ctrl + R
esc + r
esc + e
s
S
esc + s
t
T
u
esc + u
ctrl + U
v
V
\
@
?
space
-
^
$
!
:
.
/
esc + /
return
P
esc + P
esc + k
ctrl + K
ctrl + F

Useful key remaps

These need to be placed in your muttrc file. I use vim and so I want to use some of the same commands to manage my mail.

# Does not replace and currently mapped keys and acts like the vim command gg and takes
# you to the top of the page
bind index gg first-entry

# Replaces the retrieval of mail from a POP server. This will take you to the bottom of
# the page, just like it does in vim
bind index G last-entry

Flags

When viewing messages in the index menu, you will see various flags such as N which mean the messages is new and D which means that the message is to be deleted. This is a short list of those flags.

flag description
! Message is flagged
* Message is tagged
+ Message is To: you and only you
C Message is Cc: to you
d Message has attachments marked for deletion
D Marked for deletion
F Message is From: you
K Contains PGP key
L Message is sent to a subscribed mailing list
n Thread contains new messages (Only when thread is collapsed)
N Message is new
o Thread contains old messages (Only when thread is collapsed)
O Message is old
P Message is PGP encrypted
r Message has been replied to
s Message is signed
S Message is signed and verified
T Message is to you and has others in To: or Cc:

nmap

Scan a Port

nmap -p 80 google.com

openssl

Generate Self-Signed Certificate and Private Key

openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt

Other

Using less instead of tail

less +F -R /path/to/logfile.log
  • To scroll up and down, press <ctrl>+c
  • Return to tail mode, press F

The +F says to follow? The -R will process any ANSII color codes.

tmux

ctrl + b is default to enter before you enter the commands. M = Left Alt key or ESC key

Windows

command description
c Create a new window.
& Kill the current window.
n Change to the next window.
p Change to the previous window.
, Rename the current window.
l Move to the previously selected window.
w Choose the current window interactively.
M-n Move to the next window with a bell or activity marker.
M-p Move to the previous window with a bell or activity marker.

Panes

command description
" Split the current pane into two, top and bottom.
% Split the current pane into two, left and right.
x Kill the current pane.
; Move to the previously active pane.
o Select the next pane in the current window.
! Break the current pane out of the window.
q Briefly display pane indexes.

Other

command description
d Detach the current client.
$ Rename the current session.
[ Enter copy mode to copy text or view the history.
f Prompt to search for text in open windows.
r Force redraw of the attached client.
L Switch the attached client back to the last session.
$ Rename Current Session
: Enter the tmux command prompt
? List all key bindings
f Search window titles and goto that window
i Briefly display window information
r Force redraw of the attached client.
s Select a new session for the attached client interactively.
t Show the time.
= Choose which buffer to paste interactively from a list.
] Paste the most recently copied buffer of text.

Create a new session

Any of these will work.

tmux
tmux new
tmux new-session

Reattach to a session

Any of these commands will work.

tmux at
tmux attach
tmux attach-session

List sessions

Any of these commands will work.

tmux ls
tmux list-sessions

How to copy and paste

  1. Enter copy-mode C-b [
  2. Move to text, press Space to select text, move cursor to highlight text
  3. Press Enter
  4. Back at the command prompt, press C-b ] and the text you selected is pasted

References

UML

<<interface>>
<<abstract>>
<<concrete>>

- private
# protected
+ public

name : type = default value

Examples:

<<abstract>>
Name\Space\To\ClassAbstract
---
- $privateAttribute : string = ''
# $protected : integer = 1
+ $public : string = 'DefaultValue'
---
+ getPrivateAttribute() : string
+ getValueForKey($key : string) : mixed
+ get($key : string, $default : mixed = null) : mixed
Class A "uses" Class B
[Class A]- - - ->[Class B]
Class A "has a" Class B
[Class A]---->[Class B]
Company "owns" Employee
[Company]⃟----[Employee]
Ford "is a" Car
[Car]◁----[Ford]

vim

Open a file

command description
vim + file.ext Open file at last line
vim +42 file.ext Open file at line 42
vim +/^include_path Open the file at the line that starts with include_path

Exiting

command description
:q Quit
:wq Write and Quit
:q! Quit without saving
ZZ Write and quit
ZQ Quit without saving

Moving

command description
b Move to the BEGINNING of the word
e Move to the END of the word
ge Move to the END of the PREVIOUS word
gg Move to START of buffer
G Move to END of buffer
h Move cursor LEFT
j Move cursor DOWN
k Move cursor UP
l Move cursor RIGHT
n gg OR n G Move to n line (n represents a digit)
w Move to the start of the next word
ctrl+b Move BACK one page
ctrl+f Move FORWARD one page

Inserting Text

command description
a append after the cursor
A append at end of line
i Insert before cursor
I Insert before line
o Create new line below and start editing
O Create new line above and start editing
gi Place cursor where you were last editing (Useful for when you exit Insert mode and then need to go back where you once were)

Other Commands

command description
u undo
ctrl + R redo

Buffers

command description
:ls List current buffers
:bn Next buffer
:bp Previous Buffer
:bd Close Buffer

Tabs

command description
:tabnew create new tab
:tabn move to NEXT tab
:tabp move to PREVIOUS tab
:tabfir goto FIRST tab
:tablas goto LAST tab

Windows

command description
ctrl + w s Split window horizontally
ctrl + w v Split window vertically
ctrl + w q Close current window, if last window then exit vim
ctrl + w c Close current window, will not exit vim
ctrl + w o Make window the only window on the screen

Spell Checking

" ~/.vimrc
" Enable spell checking
set spell

Commands

command description
]s Move to next misspelled word
[s Move to previous misspelled word
z= Show list of possible replacements words

Marcos

  1. Press q then press another key that you want to assign it to. Example: qq
  2. Enter commands
  3. Press q when finished
  4. To run the macro, press @ and then the key that it is assigned to. Example @q
  5. NOTE: Can be ran multiple times. Enter the number of times you want it to run then the macro. Example 10@q will run the macro 10 times.

Code Folding

command description
zo OPEN code fold under cursor
zc CLOSE code fold under cursor
zR OPEN ALL code folds
zM CLOSE ALL code folds

Marks

command description
ma Create mark a in file
'a Jump to mark a
d'a Delete line mark a
:marks List marks
:delmarks a Deletes mark a
:delmarks! Deletes all marks

Auto complete

command description
ctrl + x ctrl + o Autocomplete current word
ctrl + x ctrl + n word completion next
ctrl + x ctrl + p word completion previous
ctrl + x ctrl + f Complete filename
ctrl + x ctrl + l Whole line completion

Enable

" ~/.vimrc
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete

Multi Liners

:set tw=80                  Sets text width to 80 characters
    gg                      Goto first line
    gqG                     Format file till you reach the last line

zsh

Still haven't got around to digging in a reading the man pages for this yet.

Suggesting duckduckgo to use these cheat sheet. I hope you can assist in creating the cheat sheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment