96 lines
2.9 KiB
Markdown
96 lines
2.9 KiB
Markdown
# Cheatsheet
|
|
|
|
Default Vim/Neovim bindings and commands worth remembering.
|
|
|
|
## Insert mode
|
|
|
|
- `<C-T>`: indent (`:h i_CTRL-T`)
|
|
- `<C-D>`: un-indent (`:h i_CTRL-D`)
|
|
|
|
## Normal mode
|
|
|
|
- `H` / `M` / `L`: jump to highest / middle / lowest line in window
|
|
- `<count?><C-E>`: scroll window down `<count>` lines (`:h CTRL-E`)
|
|
- `<count?><C-Y>`: scroll window up `<count>` lines (`:h CTRL-Y`)
|
|
- `<C-A>`: increment
|
|
- `<C-X>`: decrement
|
|
- `<C-w>H` / `J` / `K` / `L`: move window left / down / up / right
|
|
- `gq{motion}`: format word-wrap over `{motion}`
|
|
- `{Visual}gq`: format word-wrap of the visual selection
|
|
- `gqq`: format word-wrap of the current line
|
|
- `q:`: open the command-line window (edit and re-run past `:` commands;
|
|
`<CR>` executes the line, `:q` closes)
|
|
- `q/` / `q?`: same, for forward / backward search history
|
|
|
|
## Cmdline mode
|
|
|
|
- `<C-f>`: open the command-line window for the cmdline being typed
|
|
(`'cedit'`, default `<C-f>`). Same window as `q:` but reached without
|
|
leaving cmdline mode.
|
|
|
|
## Commands
|
|
|
|
### Quickfix list
|
|
|
|
- `:make`: run `makeprg`, put output in the quickfix list
|
|
- `:grep`: run `grepprg`, put results in the quickfix list
|
|
- `:helpgrep {pattern}`: search all help files, put matches in the quickfix
|
|
list
|
|
- `:cex {expr}`: build a quickfix list from `{expr}` and jump to the first
|
|
entry, e.g. `:cex system('make')`
|
|
- `:cgete {expr}`: like `:cex` but don't jump to the first entry
|
|
- `:copen`: open the quickfix window
|
|
- `:cdo {cmd}`: run `{cmd}` on each valid quickfix entry. Equivalent to:
|
|
|
|
```
|
|
:cfirst
|
|
:{cmd}
|
|
:cnext
|
|
:{cmd}
|
|
...
|
|
```
|
|
|
|
- `:cfdo {cmd}`: like `:cdo` but once per file
|
|
- `:cn` / `:cp`: next / previous entry that includes a filename (bound to
|
|
`]q` / `[q`)
|
|
- `:cnf` / `:cpf`: next / previous entry in a different file (bound to
|
|
`]<C-q>` / `[<C-q>`)
|
|
- `:clast` / `:crewind`: last / first entry (bound to `]Q` / `[Q`)
|
|
- `:cc [num]`: jump to entry `[num]`
|
|
|
|
### Location list
|
|
|
|
The location list is per-window. Otherwise it mirrors the quickfix commands.
|
|
|
|
- `:lmake` / `:lgrep`: like `:make` / `:grep` but into the location list
|
|
- `:lex {expr}` / `:lgete {expr}`: like `:cex` / `:cgete`
|
|
- `:lopen`: open the location-list window
|
|
- `:ldo {cmd}` / `:lfdo {cmd}`: like `:cdo` / `:cfdo`
|
|
- `:lne` / `:lp`: next / previous entry (bound to `]l` / `[l`)
|
|
- `:lnf` / `:lpf`: next / previous entry in a different file (bound to
|
|
`]<C-l>` / `[<C-l>`)
|
|
- `:llast` / `:lrewind`: last / first entry (bound to `]L` / `[L`)
|
|
- `:ll [num]`: jump to entry `[num]`
|
|
|
|
### Editing
|
|
|
|
- `@:`: repeat last command-line
|
|
- `:s/foo/bar/`: substitute the first match in the current line
|
|
- `:s/foo/bar/g`: all matches in the current line
|
|
- `:%s/foo/bar/g`: all matches in the buffer
|
|
- `:%s/foo/bar/gc`: all matches in the buffer, prompting per match
|
|
|
|
### Misc
|
|
|
|
- `:diffsplit <other-file>`: open a diff split
|
|
- `:lua << EOF ... EOF`: lua heredoc, e.g.
|
|
|
|
```vim
|
|
:lua << EOF
|
|
local tbl = {1, 2, 3}
|
|
for k, v in ipairs(tbl) do
|
|
print(v)
|
|
end
|
|
EOF
|
|
```
|