Shell Cheatsheet


Format table    %!column -t
format python   !python -m json.tool


<C-h><C-w><C-u>     Insert mode go back, works for bash
<C-o>               Insert Normal Mode(wtf?) 
db                  Delete a word backward:
10<C-a>             add number with count
xp                  Transpose next two characters
:t                  copy
:t$                 copy to end of file
gi                  go to last place text is inserted


<C-w>s   split
<C-w>v   vertical split
<C-w>c   close window
<C-w>o   keep only active window


// create new buffer
:new        new window
:enew       current window


find a file recursively under same directory
:e **/test/

check current dir

:h Head of the file name (the last component and any separators removed)
    % file path

get current dir's other files
    :edit %:h<Tab>

find file by setting search path
    find *file
    set path+=~/Dropbox/journal/**

write to nonexist dir
    :!mkdir -p %:h; write

go to file under cursor
    gf {file_name}

edit file under cursor in a new window

put current file path

read a file
    r file.txt


simply containers that hold text

addressing a register

yank word to the "a" register

    "0      yank register
    "a-z    named register
    "+      system clipboard
    "*      selection
    ":      last Ex command
    ".      last inserted text
    "/      last search pattern

Paste register in inserted mode:
    <C-r>0  yank register
    <C-r>"  unmaned register
?  search backward
/  search forward
:nohlsearch  disable highlight temporarily
<C-r><C-w>    auto-complete in search
/word/e  offest search
//e      reuse last search and put cursor at end


\c   search case insensitive
\C   search case sensitive
\v   very magic search, can use \x
\V   very no magic search
<word>  set word boundry


Special Characters

  \r    carriage return
  \t    tab
  \1    first submatch
  \2    second submatch
  \0 or &    entire submatch
  \={Vim script}  evalute script use result as replacement   decouple search and substitute, search with last search 
  %s//[word]/g   repeat last search and keep flags
  :&&   short hand for entire file

global command



reverse global (:vglobal)

yank all match line into register a.

Using uppercase A to append to register a for each line.
    :g/TODO/yank A

Append to end of file

For each range of lines beginning with {start} 
and ending with {finish}, run {cmd}
    :g/{start}/ .,{finish} {cmd}


repeat last command to visual selection
:'<,'>normal .

Vim’s grammar has just one more rule: when an operator command is invoked in duplicate, it acts upon the current line. 

More writing at