Skip to content

Instantly share code, notes, and snippets.

@dontlaugh
Forked from lambda-mike/kakoune_cheatsheet.md
Last active May 29, 2022 23:05
Show Gist options
  • Save dontlaugh/d8758ab6f2bbd4d43961a6474ff52f32 to your computer and use it in GitHub Desktop.
Save dontlaugh/d8758ab6f2bbd4d43961a6474ff52f32 to your computer and use it in GitHub Desktop.
Kakoune cheatsheet (forked from lambda-mike)
# Kakoune
set verbose mode (good for learning)
`:set -add global autoinfo normal`
## Movement
### Goto
`10g` - go to line 10
`g` +
`g` - buffer start
`e` - buffer end
`j` - buffer bottom
`t` - window top
`c` - window center
`b` - window bottom
`l` - line end
`h` - line begin
`i` - line non blank start
### Align screen relative to cursor (Vim z+)
`v` +
`v` - center vertically
`m` - center horizontally
`t` - top
`b` - bottom
`h`, `j`, `k`, `l` - scroll one char
### Search
`/ <a-/>` - start search forward (backward)
`n <a-n>` - search next search pattern forward (backward)
`N <a-N>` - extend next search pattern forward (backward)
### Selections
`%` - select whole buffer
`s` - select (find) regex in selected text
`<a-S>` - select first and last char of selection(s)
`<a-s>` - split selection on line ends
`S` - split selection on given regex
`x` - select line (`X` - next line below)
`<a-x>` - extend selections to whole lines
`<a-X>` - crop selections to whole lines
`<a-;>` - switch anchor and cursor
`;` - collapse selection to its anchor (one char, effectively reduce selection to one char)
`<a-i>` - select inner object
`<a-a>` - select all object (paragraph, sentence, etc)
`[` - select to beginning of an object; `<a-[` - inner object
`{` - extend to beginning of an object; `<a-{` - inner object
`]` - select to the end of an object; `<a-]` - inner object
`}` - extend to beginning of an object; `<a-}` - inner object
`<a-s>` - split selected text on line ends
`<a-k>` - select lines matching regexp inside selection
`<a-K>` - select lines NOT matching regexp inside selection
`7G` - select to line 7
`<a-h>` - select until beginning of; line like Vim `0`
`<a-l>` - select until end of line; like Vim `$`
`m` - match paranthesis; like Vim's `%`, select parans and content inside
`<a-m>` - match parens backwards (direction)
`M` - get a selection from current cursor to next block end or rather extend to next parans included
`<a-M>` - extend to prev parens
`f` - select to next char included (`<a-f>` - prev char)
`C` - copy selection on next lines (`<a-C>` - previus lines)
`<a-&>` - copy identation
`Z` - save selection in mark register `^`
`z` - restore selections stored in register `^`
`<a-z>` - combine selection from register, confirm by hitting `a` for example
`<a-Z>` - combine selections to register
`<space>` - remove all selections except main
`<a-space>` - remove main selection
`_` - trim selections
### Text manipulation
`y` - yank
`p` - paste after (`P` before)
`<a-p>` - paste every yanked selection after selected text, keep new (pasted) selection (`<a-P>` before)
`d` - delete
`i` - instert
`c` - delete and inserst
`R` - replace selection with the content of the register
`<a-R>` - replace selected text with yanked text
`u` - undo
`U` - redo
`<a-j>` - join with next line (`<a-J>` include spaces)
`backtick` - convert to lower-case (`<a-backtick>` - swap case)
`~` - convert to upper-case
`o` - insert on new line below (`O` above)
`<a-o>` - add new line below (`<a-O>` above)
## Advanced
`)` - loop through selections (`(` backward)
`<a-)>` - rotate splitted selection clock-wise (`<a-(>` counter clock-wise)
`"m*` - save smart search (*) pattern to register `m` (`_` is a null register)
`<c-r>` - instert into the buffer value stored in the register (`%` - buffer name, etc.); numbers correspond to submatches, like `(\w+)`
`.` - repeat last insert session
`<a-.>` - repeat last selection (for example `]p`); like Vim' `;`
`Q` - start recording macro until `Esc` is hit
`q` - replay the macro (saved in the `@` register)
### Shell
`|` - modify selections by passind to the shell command which will transform them and write back (`<a-|>` will ignore results)
`!` - insert a result of the shell cmd before selections (`<a-!>` - append result)
`$` - apply predicate to selections (0 return value is considered a success); filiter them
### Tips
`|fold -w80` - wrap selection
`!date` - insert date before selection
`$xsel -bi` - copy selection to clipboard. `-bi` stands for `--clipboard --input`
`%|diff -u <c-r>% -` - compare current buffer contents with the version saved to disk
`<a-;>` insert mode -> normal mode (for one cmd) -> back, preseving selections/bindings, modes
can be deeply nested (hit Esc more than once if needed)
The couple `u` and `U` lets you move backward and forward in the last branch while their
alternative versions `<a-u>` `<a-U>` follow absolute history id which may be located
somewhere else in the history tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment