%s/<\d\d?>/0&/g|%&&|sor r/(\d{3})%(.\d{3}){3}/|%s/<00?\ze\d//g- sort ip addresses%! jq .reformat jsonJjoin selected lines or present and next line if no seelectiongJas above but do not adjust/remove whitespacegvredo visual selection:%s/\s\+$//Delete unwanted white space (at the end of lines):%s/,([^ ])/, \1/gAdd spaces after commas:s/MATCH/&ADDapend ADD after MATCH%s/".{-}", //g.{-} non greedy match e.g. "foo", 1, "bar", 2 -> 1, 2:[RANGE]g/MATCH COMMAND1 | COMMAND2...for lines matching MATCH (in RANGE) execute COMMAND1, COMMAND2 etc.:g/MATCH/dDelete all lines containing MATCH (remove d to show lines):g/^\s*$/dDelete all blank lines:g!/^\s*H/dDelete all lines that are not commentsg/^/t.duplicate linesg/^/matches all linestcopy and paste on.line below:g/param/ copy . | s//type/gCopy lines matching param add new line below substituting type for param -:[RANGE}t Ncopy RANGE lines then paste at line N"0ppaste last yanked text: the 0 register contains only yanked text not deleted text, and is populated automatically without"0yhaving to be used''jump back to previous position at beginning of line``jump back to previous positionCtrl + o, Ctrl + iMove back and forth in jump listg; / g,move back- and forward in the list of your previous edit locationsg_last non-whitespace charAjump to end of line and appendIjump to beginning of line and insertoInsert a new line after the current one and enter insert modeOInsert a new line before the current one and enter insert mode0start of line vs^first non white space[n]|jump to n columnf[x]jump to next occurrence of character xt[x]jump to one character before the character xin normal mode jump to next non space character on the line after-in normal mode jump to next non space character on the line before)jump to next sentence. In Python files approximately blank line or code block- <code( jump to previous sentence
}jump to next paragraph (next blank line)- <code{ jump to previous paragraph
]]jump between braces? In Python files next line with char at col 1 (so class or def (if function not method)
- <code[[ as above but up
gg=Greindent the whole fileq:edit command line(s)q/,q?edit search string(s)- Visually select then
: sort uSort lines (Pressing : in visual mode inserts'<,'>) :!python -c "CODE GOES HERE"execute code (also !bash):%!python -c "CODE GOES HERE"execute code and replace file contents%can also be.for current line, range etc- type python code, visually select, then
:!pythonexecutes python code and replaces it with its own output :[range]pydo {body}execute body for each line in range
zatoggle fold (1 level)zcclose fold (1 level)zoopen fold (1 level)zAtoggle all nested folds at this levelzCclose all nested folds at this levelzOopen all nested folds at this levelzrreduce (open) folds one level throughout bufferzRopen all foldszmclose one more level of folds throughout bufferzMclose all folds
work on commandline, inc vims commandline mode
- Ctrl left/right: move to next word/argument
- Ctrl u; clear line
- Ctrl w: delete word before cursor
- Ctrl k: delete to end of line
- ctrl W + r: rotate window down/right
- ctrl W + R: rotate window up/left
- ctrl h: move cursor to next window(right)
- ctrl l: move cursor to previous window(left)
ysiw"Surround text with " when cursor is in word " can be repalced with anything inc tags <em> etcS"Surround selected text with " etccs"'Replace " with 'ds"Delete "cst"replace tag with "yss"wrap entire line with "cs")replace " with ( & )cs"(replace " with ( & ) and space inside ( & )ysl<space><space>surround a single character with spacesS<space><space>in visual mode
git add -u .add modified and deleted only, for current directorygit add -u /file/pathadd modified and deleted only, for path :/ is base i.e. all of repogit add -uadd modified and deleted only, for all of repgit branch --mergedshow merged branchesgit branch --remotesshow remote branchesgit branch -m OLD NEWrename (--move) branchgit checkout -checkout previous branchgit checkout -- [file]revert an unstaged file to last commitgit checkout [branch_name] -- [path to file]checkout file from another branchgit clean -X -fcleanup files in gitignoregit commit -a[m] [file]Add and commitgit config --global alias.[alias] "[git options]"git aliasgit config --global push.default simpleadopt new push behaviour -- only push branch you are ongit diff $start_commit..$end_commit -- [path/to/file]diff between commitsgit diff --cachedcompares staged(i.e. files staged with git add) and HEADgit diff --color-wordshighlight words changed in linesgit diff --name-only --diff-filter=UShow files with merge conflictsgit diff --stagedsynonym for --cachedgit diff HEAD [file]Show the differences between your working directory and the most recent commit, includes files git addedgit diff HEAD^^ HEAD file.pydiff between now and two commits agogit diff mybranch master -- myfilediff between branchesgit fetch ;git checkout test(git checkout -b test remote-name/test with multiple remotes) checkout remote branchgit fetch; git checkout --track origin[branch]checkout remote branchgit log --first-parentRoughly exclude commits from merged in branchgit log --graph --decorate --pretty=one-line --abbrec-commit --allgit log --name-onlyShow names of files changedgit log --patchshow patchgit log --stat --decorate --graph --decorate --all --onelinegit log --all --grep='[given-text]'search commit logsgit log --no-merges --raw --since='2 weeks agoalternativelyit whatchanged --since='2 weeks ago' git log --all --git pull --pruneprune deleted branches on remotegit pull --rebaseuse if you can't pullfatal: Not possible to fast-forward, aborting.git push -u origin-u : set upstream trackinggit refloglog of all places HEAD has been (tracks resets, reverts etc)git reset --hardReset to last commit remove changes, remove historygit reset --soft HEAD~2; git commit --amendGo back two commits and then amend that commit with the changes in later commits.git reset --softReset to last commit keep changes in files and keep them staged, remove historygit reset --softReset to last commit keep changes in files and unstaged, remove historygit revert [hash]revert commit (add to history) -git stash show -p | git apply -RUndo a git stash apply (as long as no subsequent changes have been made)git update-index --assume-unchanged path/to/fileignore local changes to comitted filegit update-index --no-assume-unchanged path/tofilestrack changes againgit update-index --skip-worktree [file]Ignore local changes to tracked file(e.g. config file), takes preference over assume-unchanged
PPA for latest stable git
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install gitfoo -‹tab›‹tab›Show argument optionskill foo‹tab›Suggest process to killscp foo@barFile completions with scp if public key enabledfoo‹up› or ‹down›Type string then press up or down to search history ifhistory-substring-searchplugin enabled.<esc> v-- enter editor mode. i.e. edit command line in vi(m) needs:autoload edit-command-line; zle -N edit-command-line; bindkey '\ev' edit-command-linein .zshrc
-
![command]run last version of [command] -
![command]:pprint last version of [command] -
!$arguments from last command -
!! s/one/two/run last command substituting two for one -
^commnad^command^search and replace on last command -
mv /path/to/file.{txt,xml}file.txt -> file.xml -
cp /etc/rc.conf{,-old}rc.conf -> rc.conf-old -
mv /etc/rc.conf{-old,}rc.conf-old -> rc.conf -
mkdir myfolder{1,2,3}folder1, folder2, folder3 -
[COMMAND] | sed -r "s/\x1B[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g"remove coloured output
tmux rename-session [-t [old-session]] [session-name]
###tswitch Replace the current session with a detached one. Useful if you autostart tmux, and e.g. want to switch back to a session after your connection dropped.
#!/bin/bash
new_session=$(tmux display-message -p "#S")
tmux switch-client -t $1
tmux kill-session -t $new_session- move a window in a split plane: Hold CMD-SHIFT-OPT (WINKEY-SHIFT-ALT) and drag the pane
// eslint-disable-next-line no-use-before-define
docker-compose up --detach --renew-anon-volumes --no-deps --force-recreate --build [service]rebuild and start docker service forcing it to completly rebuiddocker-compose up -d [service](-d, --detach) start and run in backgrounddocker ps -ashow all containers (not just running)docker ps -a -f status=exitedShow exited containersdocker rm id_or_nameremove containerdocker images -ashow all images including intermediatedocker rmi image_idremove imagedocker images -f "dangling=true" -q)Show dangling imagesdocker image pruneRemove dangling imagesdocker rmi $(docker images -f "dangling=true" -q)Delete dangling imagesdocker volume ls -f dangling=truelist dangling volumesdocker volume rm $(docker volume ls -f dangling=true -q)remove dangling volumes- direct download for Mac: https://download.docker.com/mac/stable/Docker.dmg (no registration)
"".join(" \t foo \n bar ".split())->'foobar'Strip all white space characters- Shell complains about virtualenv wrapper e.g. after brew upgrade:
sudo pip3 install virtualenv virtualenvwrapperthen source .zshrc etc. Error message:Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper') virtualenvwrapper.sh: There was a problem running the initialization hooks.
pyenv install [version]not working on Mac? Try:brew uninstall binutils
- rename a field with out migrations:
old:
my_field = models.Field()new:
_my_field models.Field(db_column="my_field")
(presume this should by _new_field = ... but I haven't touched Django in a long time, now.
optionally:
@property
def my_field(self):
return self._my_fieldOperationalError: (2006, 'MySQL server has gone away')
import django.db
django.db.close_old_connections()
object?get help about object: docstrings etc%editedit in temporary file with editor%edit -popen editor with data from last time it was used in session%run script.pyrun script and print results%debugactivate debugger%save file.py 1-2 4-6save specified lines to file%recall 1recall line no (like ! in shell)%history [ 20-22]/[-1/4]print input history [these lines]/[line for from last session]%timeit!shell_cmdrun shell cmdouput = !shell_cmdsave output of shell cmd to a python variable
%load_ext autoreload
%autoreload 2Reload all modules (except those excluded by %aimport) automatically now.
| Command | Meaning |
|---|---|
%autoreload 0 |
Disable automatic reloading. |
%autoreload 1 |
Reload all modules imported with %aimport every time before executing the Python code typed. |
%autoreload 2 |
Reload all modules (except those excluded by %aimport) every time before executing the Python code typed. |
%aimport |
List modules which are to be automatically imported or not to be imported. |
%aimport foo |
Import module ‘foo’ and mark it to be autoreloaded for %autoreload 1 |
%aimport -foo |
Mark module ‘foo’ to not be autoreloaded. |
Install nbextensions:
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
Install Vim Bindings:
mkdir -p $(jupyter --data-dir)/nbextensions
cd $(jupyter --data-dir)/nbextensions
git clone https://github.com/lambdalisue/jupyter-vim-binding vim_binding
Activate:
Permanent
jupyter nbextension enable vim_binding/vim_binding
Activate from a notebook (optional)
%%javascript
Jupyter.notebook.config.update({
'load_extensions': { 'vim_binding/vim_binding': true },
});
Productivity unlocked!
<f1>: show key bindings- Enter Vim mode (a super mode of Vim command mode and Insert mode) (note appears to be automatic when clicking on cell)
- (Double) click a cell
- <Enter> in a cell
- Hit i on a cell
- Leave Vim mode and re-enter Jupyter mode by hitting
<S-Esc>(Shift-Escape) - Enter Insert mode or leave Insert mode as like Vim (
i,a, etc.) :wsave and checkpointyyyank cellCtrl + norCtrl + p: completionCtrl + g: tooltipj/k etcnext/previous cell