Digital Garden

Vim Grimoire

Grimoire for VIM commands

File Management


:q      close
zq      quit all
zz      save and quit

Nerd Tree:

<ctrl>+n            toggle nerd tree
o/O                 open file or directory / open recursively
x/X                 close file or directory / close recursively
c                   open directory in new NDT pane
C                   make directory root
u/U                 move root directory up / move but stay
r/R                 refresh directory / refresh root
p/P                 go to parent / go to root
f                   toogle file filters
:Bookmark [<name>]  add book mark with name
D                   delete bookmark
m                   new, delete, or move files

Split & Tab Management


<ctrl>+h  hop left
<ctrl>+j  hop down
<ctrl>+k  hop up
<ctrl>+l  hop right

:sp     open horizontal split
:vsp    open vertical split

<ctrl>+w o    fullscreen pane


gt      next tab
gT      last tab
tabm #  go to tab #


s       open in vertical split
i       open in horizontal split
t       open in tab

Fuzzy File Open

<ctrl>+p    start file search
<ctrl>+v    open in vertical split
<ctrl>+s    open in horizontal 
<ctrl>+t    open in tab
<ctrl>+y    creae a new file


zc  closes fold


Vim Modes:

a/e/i       insert mode
escape      command mode
v           visual mode
<ctrl>+v    block visual mode
f3      toggle numbers


Marks allow us to dog ear a spot in the code to return.

m+[a-z]         Add a mark in the file at this point
m+[A-Z]         Add a global mark at this point
'[a-zA-Z]       Return to line of the mark
`[a-zA-Z]       Return to the exact position of the mark
:marks          Show current marks
:delm [a-zA-Z]  Delete the marka
:delm!          Clear all marks


Registers are where text that has been deleted or cut goes

"a y    Add register A for text yanked by y
"a p    Put text in register a
0-9     Registers for the last ten yanks/deletes

Text Manipulation


y       copy
p       paste
x       cut
space+v paste from clipboard
space+y copy to clipboard
.       Repeat last input


d       delete character
d$      delete to end of line
dGG     delete to end of file
dd      delete line


r       redo
u       undo

Search & Replace:

:%s/forest/tree   Replace forest with tree
:%s/){/\r\t{/     Add  new line between ")" and "{"
:%s/public function \(.*\))/private function \1)
    Match public function _name_ and replace with private function _name

Moving About

Character movement:

h       left
j       down
k       up
l       right

Jump about:

#G      jump to line #
^       start of line
$       end of line
b       back a word
w       forward a word


/       search
n       next search match
N       last search match

Fuzzy Search

f5          purge cache
<ctrl>+r    regex mode
<ctrl>+d    filename mode


f5      start script
f2      step over
f3      step into
f4      step out
f6      kill script
f7      detach from debugger
f9      run to cursor
f10     toggle breakpoint
f12     evaluate variable under cursor


z=      spellcheck dialog
]s      next misspelled word
[s      last misspelled word
zg      add word to dictionary
zw      mark word as wrong
zug     undo add word
zuw     undo wrong word

SQL Plug

<space>sp       select mysql preset
<space>sd       set database
<space>rf       run file
<space>rs       run statement
<space>dl       list databases
<space>tl       list tables
<space>td       describe table


<space>tt           show method/variable breakdown for class
<space>fs           fix highlighting
q+[a-z]             start/stop recording macro
<space>gc           toggle comment
<space>gw           format to line length
<space>pd           start doc block
<space>fj           format json
<space>fr           format sql
<space>a+[^|<>l::|] fix alignment
<shift>+k           open documentation in pane

<ctrl>+x <ctrl>+f   open file selector
<ctrl>+n            start autocomplete
<ctrl>+n, <ctrl>+p  cycle through autocomplete options

Linked References