From 0766c7f11ec12c0873700369ccb1b48e0723ef0d Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Wed, 29 Apr 2026 10:14:36 +0200 Subject: [PATCH] docs: extract keymap cheatsheet into CHEATSHEET.md --- CHEATSHEET.md | 84 +++++++++++++++++++++++++++++++++++++++++++++ lua/core/keymap.lua | 54 ----------------------------- 2 files changed, 84 insertions(+), 54 deletions(-) create mode 100644 CHEATSHEET.md diff --git a/CHEATSHEET.md b/CHEATSHEET.md new file mode 100644 index 0000000..53a78b7 --- /dev/null +++ b/CHEATSHEET.md @@ -0,0 +1,84 @@ +# Cheatsheet + +Default Vim/Neovim bindings and commands worth remembering. + +## Insert mode + +- ``: indent (`:h i_CTRL-T`) +- ``: un-indent (`:h i_CTRL-D`) + +## Normal mode + +- `H` / `M` / `L`: jump to highest / middle / lowest line in window +- ``: scroll window down `` lines (`:h CTRL-E`) +- ``: scroll window up `` lines (`:h CTRL-Y`) +- ``: increment +- ``: decrement +- `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 + +## Commands + +### Quickfix list + +- `:make`: run `makeprg`, put output in the quickfix list +- `:grep`: run `grepprg`, put results 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 + `]` / `[`) +- `: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 + `]` / `[`) +- `: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 `: 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 + ``` diff --git a/lua/core/keymap.lua b/lua/core/keymap.lua index a42ff85..51da8b5 100644 --- a/lua/core/keymap.lua +++ b/lua/core/keymap.lua @@ -145,9 +145,6 @@ vim.keymap.set("n", "r", function() end end) -vim.keymap.set("n", "]c", ":cn") -vim.keymap.set("n", "[c", ":cp") - vim.keymap.set("n", "", vim.diagnostic.open_float) vim.keymap.set("n", "[d", function() vim.diagnostic.jump({ count = -1, float = true }) @@ -232,54 +229,3 @@ vim.keymap.set("n", "fd", vim.diagnostic.setloclist) vim.keymap.set("n", "fD", vim.diagnostic.setqflist) vim.keymap.set("n", "grt", vim.lsp.buf.type_definition) vim.keymap.set("n", "gd", vim.lsp.buf.definition) - --- Default bindings that are good to know: --- insert mode: --- - indent, see :h i_CTRL-T --- - un-indent, see :h i_CTRL-D --- normal mode: --- H/M/L - Jump to highest/middle/lowest line in window. --- - scroll window down lines, see :h CTRL-E --- - scroll window up lines, see :h CTRL-Y --- - Increment --- - Decrement --- H - Move window to the left --- J - Move window down --- K - Move window up --- L - Move window to the right --- gq{motion} - format word-wrap of the line that {motion} moves over --- {Visual}gq - format word-wrap of the visually selected area --- gqq - format word-wrap of the current line --- commands: --- :make - execute makeprg with given args, and put the output in --- quickfix list --- :grep - execute grepprg with given args, and put the results in --- quickfix list --- :cex {expr} - Create a quickfix list using the result of {expr} and --- jump to the first error. For example: --- :cex system('make') --- :cgete {expr} - same as :cex but don't jump to the first error --- :copen - open quickfix list --- :cdo {cmd} - execute {cmd} in each valid entry in the quickfix list. --- works like this: --- :cfirst --- :{cmd} --- :cnext --- :{cmd} --- etc. --- :cfdo {cmd} - same as :cdo but on each file in quickfix list --- :cn - go to the next error in quickfix list that includes a file name --- :cp - go to the previous error in quickfix list that includes a file name --- :cc [num] - go to the specified error in quickfix list --- @: - repeat last command --- :s/foo/bar/ - substitute the first match of foo with bar in the current line --- :s/foo/bar/g - same as above but for all matches in the current line --- :%s/foo/bar/g - same as above, but for all lines in buffer --- :%s/foo/bar/gc - same as above but asking for confirmation on each match --- :lua << EOF - run a lua snippet using lua-heredoc syntax --- local tbl = {1, 2, 3} --- for k, v in ipairs(tbl) do --- print(v) --- end --- EOF --- :diffsplit - open diff split