# VIM Cheat Sheet ## Split - `s` or `:sp` or `:split` split with line running horizontally - `v` or `:vsp` or `:vsplit` split with line running verticall - `arrow` move to pane - `c` close split - `o` close all other splits - `:q` close tab - `:tab split` move split to new tab - `:sp | b1` create new split with buffer 1 ## Buffers - `:b[num]` use buffer `[num]` - `:bn` next buffer - `:[num]bd` unload buffer `[num]` ## Tabs - `gt` go to next tab - `gT` go to next tab - `[num]gt` go to tab `[num]` - `:tabnew` open new tab - `:tabc` close tab - `:tabe` edit file in new tab ## Auto Complete - `` omni completion - `,` emmet - `` abbreviations - `` word completion ## Navigation ### Cursor - `hjkl` - move - `w` - move to next word - `b` - mve to previous word - `H` move to top of screen - `M` move to middle of screen - `L` move to bottom of screen ### Screen #### Paging - `` page down - `` page up - `` half page down - `` half page up #### Scrolling - `` to move the screen up one line. - `` to move the screen down one line. #### Adjusting Current Line Placement - `zz` to move the current line I'm on to the center of the screen. - `zt` to move the current line I'm on to the top of the screen. - `zb` to move the current line I'm on to the bottom of the screen. #### Move Screen to Specified Line Number - `[num]zz` to move indicated line to the center of the screen. - `[num]zt` to move indicated line to the top of the screen. - `[num]zb` to move indicated line to the bottom of the screen. ## Editing - `dw` delete forward to end of word - `db` delete backward to beginning of word - `D` delete to end of line - `d^` delete to beginning of line - `dvb` delete backward to beginning of word including current char - `x` delete current char - `X` delete previous char ## Search - `:vim a *.*` - search for 'a' in all files in dir - `:copen` / `cclose` open quickfix list to view matches of `:vim` - `/` find - `n` find next match - `N` find previous match - `:noh` stop search highlight - `:%s/wordtochange/changedvalue/gc` search/replace ## Copying - `"+y` copys visual selection to clipboard - `yy` copys entire line - `[num]yy` yank `[num]` lines - `yb` yank previous word - `yw` yank next word ## Formatting - `=` auto indent selection/line - `gg=G` auto indent entire buffer - `J` join current line with next line ## Comments - `\c` - Nerdcommentor - `` then select block. Then `` to enter insert. Enter text and hit `Esc` ## Selection - `v` visual character - `V` visual line - `` visual block - `` visual block, highlight from start to click point ## Commands - `:%s/\s\+$//e` trim ending whitespace - `:%retab!` convert spaces to tabs - `NERDTree` open up nerd tree file explorer ## NERDTree - `r` refresh tree