You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[[link][description]]
# or alternatively
[[link]]
# image
[[image]]
“TODO” Items
<Ctrl-c> <Ctrl-t>
rotate the state of the current item
<Shift-Up/Down>
raise/lower priority
<Ctrl-c> <Ctrl-c>
toggle checkbox at point (- [ ] subtask)
<Meta-Shift-Enter>
insert new TODO entry (TODO |\vert - [ ])
repeated tasks
** TODO Pay the rent
DEADLINE: <2005-10-01 Sat +1m>
where y/w/m/d/h can be used
timestamps
<Ctrl-c> .
prompt for a timestamp
<Ctrl-c> !
prompt for an inactive timestamp
<Ctrl-c> <Ctrl-d>
insert DEADLINE timestamp
<Ctrl-c> <Ctrl-s>
insert SCHEDULED timestamp
<Shift-Right/Left>
change timestamp at cursor ±1 day
<Shift-Up/Down>
change year/month/day at cursor by ±1
<Ctrl-c> >
access the calendar for the current date
<Ctrl-c> <
insert timestamp matching date in calendar access agenda for current date
agenda
<Ctrl-c> <a> <a>
agenda view
<l>
log view
<q>
quit
code blocks
<Ctrl-c> <Ctrl-c>
execute code block under cursor
format
*+BEGIN_SRC org
+BEGIN_SRC org
echo “This file takes up `du -h emacs.md | sed ‘s/\([0-9k]\)[ ]*emacs.md/\1/’`”
*+END_SRC
*+END_SRC
supported languages
Language
Identifier
Language
Identifier
Asymptote
asymptote
Awk
awk
C
C
C++
C++
Clojure
clojure
CSS
css
D
d
ditaa
ditaa
Graphviz
dot
Emacs Calc
calc
Emacs Lisp
emacs-lisp
Fortran
fortran
gnuplot
gnuplot
Haskell
haskell
Java
java
Javascript
js
LaTeX
latex
Ledger
ledger
Lisp
lisp
Lilypond
lilypond
MATLAB
matlab
Mscgen
mscgen
Objective Caml
ocaml
Octave
octave
Org mode
org
Oz
oz
Perl
perl
Plantuml
plantuml
Processing.js
processing
Python
python
R
R
Ruby
ruby
Sass
sass
Scheme
scheme
GNU Screen
screen
Sed
sed
shell
sh
SQL
sql
SQLite
sqlite
tags
heading tags
<Ctrl-c> <Ctrl-q>
set tags for current heading
<Ctrl-u> <Ctrl-c> <Ctrl-q>
realign tags in all headings
<Ctrl-c> <\>
create sparse tree with matching
<Ctrl-c> <Ctrl-o>
tags globally (agenda) match tags at cursor
org-change-tag-in-region
set tags for selected headings
priority
<Shift-Up/Down>
set prio for header
sort
Sorting methods: Alphabetically, numerically, by time (first timestamp with active preferred, creation time, scheduled time, deadline time), by priority, by TODO keyword or by the value of a property.
Ctrl-c ^
org-sort
sorts the selected region
export
<Ctrl-c> <Ctrl-e>
export/publish dispatcher
time tracking
C-c C-x C-i
(org-clock-in)
Start the clock on the current item
C-c C-x C-o
(org-clock-out)
Stop the clock
C-c C-x C-x
(org-clock-in-last)
Reclock the last clocked task
C-c C-x C-r
(org-clock-report)
Show a report table
C-c C-x C-d
org-clock-display
Summarize times inline
workgroups2
<Ctrl-c> z
<prefix>
<prefix> c
create workgroup
<prefix> A
rename workgroup
<prefix> k
kill workgroup
<prefix> v
switch to workgroup
<prefix> C-s
save session
<prefix> C-f
load session
helm
usage
You can mark candidates with C-SPC; this is useful when you need to perform an action on many candidates of your choice (kill buffers for example). M-a to select all.
You can insert marked candidates into the current buffer with C-c C-i. This is useful when you have narrowed to a list of candidates, i.e. files, and then you want to save such candidates.
If you find the current horizontal Helm window is small, you can always switch it to a vertical window with C-t. Running C-t again returns the Helm window back to horizontal and so on.
From within a helm-find-files session, you can invoke helm-ff-run-grep with C-s to search a file/directory on highlighted entry in the Helm buffer. With prefix argument C-u, recursively greps a selected directory.
You can also save the result into a Grep buffer using the action Save results in Grep buffer. Note that this Grep buffer is created by Helm, not the default Emacs grep buffer. It has minimal key bindings. In hgrep buffer, press C-h m to view all key bindings.
git reset HEAD~
# If you don't want the changes and blow everything away:
git reset --hard HEAD~
undo added file
git checkout file
moving to a new branch
move commits to a new branch
# Note: Any changes not committed will be lost.
git branch newbranch # Create a new branch, saving the desired commits
git reset --hard HEAD~3 # Move master back by 3 commits (GONE from master)
git checkout newbranch # Go to the new branch that still has the desired commits
But do make sure how many commits to go back. Alternatively, you can instead of HEAD~3, simply provide the hash of the commit (or the reference like origin/master) you want to “revert back to” on the master (/current) branch, e.g:
git reset --hard a1b2c3d4
*1 You will only be “losing” commits from the master branch, but don’t worry, you’ll have those commits in newbranch!
moving to an existing branch
WARNING The method above works because you are creating a new branch with the first command: git branch newbranch. If you want to use an existing branch you need to merge your changes into the existing branch before executing git reset –hard HEAD~3. If you don’t merge your changes first, they will be lost. So, if you are working with an existing branch it will look like this:
git checkout existingbranch
git merge master
git checkout master
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.
git checkout existingbranch
general
reference the last branch
git checkout -
remove all deleted files
git rm $(git ls-files --deleted)
add changes to the last commit
git commit --amend
add partial
git add --partial
# git add -p
git gui
ancestry references
ref~
Shorthand for ref~1 and means the commit’s first parent. ref~2 means the commit’s first parent’s first parent. ref~3 means the commit’s first parent’s first parent’s first parent. And so on.
ref^
Shorthand for ref^1 and means the commit’s first parent. But where the two differ is that ref^2 means the commit’s second parent (remember, commits can have two parents when they are a merge).
combined
The ^ and ~ operators can be combined.
example
HEAD -> * 5. commit on master
HEAD~1 or HEAD^1 -> * Merge branch 'my_branch'
|\
HEAD~1^2 -> | * 1. commit on branch
HEAD~2 or HEAD~1^1 -> * / 4. commit on master
HEAD~3 or HEAD~2^1 -> * 3. commit on master
etc... * 2. commit on master
* 1. commit on master
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split(“&”);
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split(“=”);
// If first entry with this name
if (typeof query_string[pair[0]] === “undefined”) {
query_string[pair[0]] = decodeURIComponent(pair[1]);
// If second entry with this name
} else if (typeof query_string[pair[0]] === “string”) {
var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
}();
SELECT
address_line1, address_line2, zip, city, country, COUNT(*)
FROM
location
GROUP BY
address_line1, address_line2, zip, city, country
HAVINGCOUNT(*) >1;
delete leading whitespace (spaces, tabs) from front of each line aligns all text flush left
sed 's/^[ \t]*//'
delete trailing whitespace (spaces, tabs) from end of each line
sed 's/[ \t]*$//'
delete BOTH leading and trailing whitespace from each line
sed 's/^[ \t]*//;s/[ \t]*$//'
delete lines longer than 15 chars
sed '/.\{16\}/d'
print only lines which match regular expression (emulates “grep”)
sed -n '/regexp/p'# method 1
sed '/regexp/!d'# method 2
print only lines which do NOT match regexp (emulates “grep -v”)
sed -n '/regexp/!p'# method 1, corresponds to above
sed '/regexp/d'# method 2, simpler syntax
substitute (find and replace) “foo” with “bar” on each line
sed -i.bak 's/foo/bar/g' file.txt # make the changes inline and create a backup of the original file before it does the changes in-place
sed 's/foo/bar/'# replaces only 1st instance in a line
sed 's/foo/bar/4'# replaces only 4th instance in a line
sed 's/foo/bar/g'# replaces ALL instances in a line
sed 's/\(.*\)foo\(.*foo\)/\1bar\2/'# replace the next-to-last case
sed 's/\(.*\)foo/\1bar/'# replace only the last case
substitute “foo” with “bar” ONLY for lines which contain “baz”
sed '/baz/s/foo/bar/g'
substitute “foo” with “bar” EXCEPT for lines which contain “baz”
sed '/baz/!s/foo/bar/g'
change “scarlet” or “ruby” or “puce” to “red”
sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g'# most seds
gsed 's/scarlet\|ruby\|puce/red/g'# GNU sed only
reverse order of lines (emulates “tac”)
# bug/feature in HHsed v1.5 causes blank lines to be deleted
sed '1!G;h;$!d'# method 1
sed -n '1!G;h;$p'# method 2# reverse each character on the line (emulates "rev")
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
join pairs of lines side-by-side (like “paste”)
sed '$!N;s/\n/ /'# if a line ends with a backslash, append the next line to it
sed -e :a -e '/\\$/N; s/\\\n//; ta'# add commas to numeric strings, changing "1234567" to "1,234,567"
gsed ':a;s/\B[0-9]\{3\}\>/,&/;ta'# GNU sed
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'# other seds# add commas to numbers with decimal points and minus signs (GNU sed)
gsed ':a;s/\(^\|[^0-9.]\)\([0-9]\+\)\([0-9]\{3\}\)/\1\2,\3/g;ta'
remove leading whitespace and tabs
sed -e 's/^[ \t]*//'
remove trailing whitespace and tabs
sed 's/[ \t]*$//'
remove leading and trailing whitespace and tabs
sed 's/^[ \t]*//;s/[ \t]*$//'
edit inplace
# file.bak is the backup; file will be edited
sed -i .bak "/<pattern>/d" file
bring the background job with the job id 1 to foreground
fg %1
terminate the background job with the job id 1
kill %1
keybindings
key
description
<escape-.>
last param of the last command (repeat)
<ctrl-u> […] <ctrl-y>
type partial command, kill this command, check something you forgot, yank the command, resume typing
<alt-.>
insert previous command argument
<alt-a>
multiselect in menu complete
<alt-arrow-left>
move a word backward
<alt-arrow-right>
move a word forward
<cmd-del>
delete the word left of the cursor
<cmd-arrow-left>
move to the beginning of the line
<cmd-arrow-right>
move to the end of the line
<cmd-arrow-down>
delete the whole line
<ctrl-x>
delete the char under the cursor
<ctrl-w>
delete the word under the cursor
<alt-arrow-up>
cd ..
<ctr-l>
ls -laH
<arrow-up>
history substring search backward
<arrow-down>
history substring search forward
<ctrl-z>
suspend job to background
globbing
list all javascript files under pwd
ls **/**js
list text files that end in a number from 1 to 10
ls -l zsh_demo/**/*<1-10>.txt
list text files that start with the letter a
ls -l zsh_demo/**/[a]*.txt
list text files that start with either ab or bc
ls -l zsh_demo/**/(ab|bc)*.txt
list text files that don’t start with a lower or uppercase c
ls -l zsh_demo/**/[^cC]*.txt
show only directories
print -l zsh_demo/**/*(/)
show only regular files
print -l zsh_demo/**/*(.)
show empty files
ls -l zsh_demo/**/*(L0)
show files greater than 3 KB
ls -l zsh_demo/**/*(Lk+3)
show files modified in the last hour
print -l zsh_demo/**/*(mh-1)
sort files from most to least recently modified and show the last 3
ls -l zsh_demo/**/*(om[1,3])
expansion
parameter expansion
git diff ./file_1.py
git add !:2<TAB>* expands to git add ./file_1.py
!!* last command!$ * last parameter of the last command!** all parameters
parameter processing
one by one
*!/bin/bash
foriin"$@"docase$iin
-e=*|--extension=*)
EXTENSION="${i**=}"shift* past argument=value
;;
-s=*|--searchpath=*)
SEARCHPATH="${i**=}"shift* past argument=value
;;
-l=*|--lib=*)
LIBPATH="${i**=}"shift* past argument=value
;;
--default)
DEFAULT=YES
shift* past argument with no value
;;
*)
* unknown option
;;
esacdone
paired
#!/bin/bash# Use -gt 1 to consume two arguments per pass in the loop (e.g. each# argument has a corresponding value to go with it).# Use -gt 0 to consume one or more arguments per pass in the loop (e.g.# some arguments don't have a corresponding value to go with it such# as in the --default example).# note: if this is set to -gt 0 the /etc/hosts part is not recognized ( may be a bug )while [[ $*-gt 1 ]]
do
key="$1"case$keyin
-e|--extension)
EXTENSION="$2"shift* past argument
;;
-s|--searchpath)
SEARCHPATH="$2"shift* past argument
;;
-l|--lib)
LIBPATH="$2"shift* past argument
;;
--default)
DEFAULT=YES
;;
*)
* unknown option
;;
esacshift* past argument or value
done
reverse
files=(/var/logs/foo*.log)
for((i=${*files[@]}-1; i>=0; i--));do
bar "${files[$i]}"done
OS X
use mac apps from the shell
open -a /Applications/Whatever.app
prevent spotlight from indexing external volume
mdutil -i off /Volumes/VolumeName
locatemd: to search for a file using Spotlight’s metadata