title: 30 Vim Commands You Need To Know by typecraft tags: vim Source: [this video by typecraft](https://www.youtube.com/watch?v=RSlrxE21l_k&t=71s) + quit: `:q`, `:wq` to write and quit, `:x` does similar, `:q!` quits without saving, `:wq!` forces overwrite + search and replace: `:s/hello/world`, `:s/hello/world/g`, `:s@hello@wor/ld@g` * Read up on vim [regular expressions](/editor/vim/regex/Guide). + search: `/regex` search forward; `?regex` search backwards; `n` to go to next match (forward with `/`, backward with `?`), `N` to go in the opposite direction. + motions: `ciw` = change in word, `cw` = change to end of word, `caw` = change around word, `ciW` = change in word. + words: `w` vs `W` is syntactic vs whitespace, so e.g. `w` will see `hello+world` as two words, so `ciw` within `hello` would replace `hello`, whereas `W` will see `hello+world` as one word, so `ciW` will change all of `hello+world`. + delimiters: `b` = parens, `B` = braces; `{`, `<`, `(`, `[`, `'`, `"` and also for backquotes + visual: `v` to select characters, `V` to select rows, `` to select columns (i.e. rectangular block) + yank: `y` will copy whatever is selected, `"qy` will copy whatever is selected to register `q` + change: `c` will change whatever is selected + delete: `d` will delete whatever is selected and put it in the default register (so is kind of 'cut') + registers: + yank, delete, put: `"qy` yanks to register `q`, `"wd` cut to register `w`, `"ep` put *after* from register `e` + macros: + record: `qa...keysq` records a macro into register `a` + replay: `@a` will run macro `a`, `10@a` will run macro `a` ten times