Skip to content

Instantly share code, notes, and snippets.

@JoshKaufman
Last active April 5, 2017 17:40
Show Gist options
  • Save JoshKaufman/104eb8243fe84f0ae8df to your computer and use it in GitHub Desktop.
Save JoshKaufman/104eb8243fe84f0ae8df to your computer and use it in GitHub Desktop.
" general
m = mark position (eg ma then 'a will go back to that position)
cW/cw = change word
cB/cb = change till begining of word
C = change till end of line (delete from curser to end and go into insert mode)
A = insert at end of line
dd = del line
D = delete till end of line
I = go into insert mode at begining of line (before first non-whitespace chars)
L = goto bottom of screen
H = goto top of screen
M = goto middle of screen
S = change whole line (substitude)
U = undo all line changes (since cursor moved into line)
leader=","
:[v]sp " ([vertical] split window)
:bd "(buffer delete)
:tabnew filename? " (open new tab [with file?])
line# G (go to line number)
gt " (switch tab)
:only " (close all tabs/panes except active one)
leter q " record in buffer (leter) (use @leter to replay)
. " replay last command
visual->select(j,k,$,^...)->y/c(yank)->ctrl+r/p " (copy/paste)
:w !diff % - " (diff current buffer with file..)
" folding
zc (close fold)
zo (open fold)
za (toggle fold)
zr (reduce fold by one [open/close all at this level of indentation...])
<leader>ig " (toggle indent gutter) show indent lines
<leader>ci " (toggle comment line)
<leader>cc " (comment out line)
<leader>c$ " (comment here till end of line)
" find/replace
Ack -i --{filetype} string_to_search_for "(find case insansitive the search string in files of type filetype [can have multiple file types] ex: --coffee --json)
:%s/string_to_find/string_to_replace_width/ic "(find string in file [case-in-sensitive] replace with second string [c=interactive: it asks Y, N])
Ggrep 'find me' " (search git for string find me [with no args the benefit is it only looks in tracked files])
:Grep --cached findMe " (search for findMe in the index)
:Grep findMe branchName/tagName/SHA " (...)
:Glog --grep=findme -- " (search for ‘findme’ in all ancestral commit messages)
:Glog --grep=findme -- % " (only commits that touched the currently active file)
:Glog -Sfindme -- " (search for ‘findme’ in the diff for each ancestral commit)
:Glog -Sfindme -- % " (search for ‘findme’ in the diff for each ancestral commit that touches the currently active file)
" fugitive
Gstatus " (fugitive git status)
ctrl n, p " (move to next/prev files in status)
Gdiff " (fugitive git diff)
diffget " (pull the change from other file)
diffput " (push the changes to other file)
Glog -10 " (fugitive git log last 10 changes [width :cnext ]q to show next cprev [q ?])
Glog -- " (all changes [use file path to filter for file...])
Glog -- % " (all changes in parent commits to this file..)
Ggrep " look at find_and_replace
" maps
ctrl h, j, k, l, (navigate between panes)
* (find next instance of word under cursor)

vim RegExp(s)

%s /_find_/_replace_/gc (case-insensitive and ask for each instance)

All regexp chars need to be escaped \^, \(, \) etc

\0 full match, \1 first group, \2 second etc..

%s /^\(\s\+\)\([^:]\+\):/\1"\2":/gc - begining of line find all spaces followed by string followed by colon, replace with space + " + string +":

%s /,\(\_s\+\)]/\1}/gc - find all commas at end of line that are followed by whitespace and closing }|] IE to make a js object valid json

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