neovim/CHEATSHEET.md

122 lines
3.8 KiB
Markdown

# Neovim cheat sheet
Heavily customized. Related blog post: https://lugh.ch/neovim-lessons-learned.html
## BASICS
- `:che [<pluginname>]` check base or plugin status
- `:che lsp` show LSP details
- `:verbose set expandtab?` check where `expandtab` was set last
- `:Lazy` package manager
- `:Mason` LSP management
- `:TSUpdate` update Tree-sitter parsers
- `:ConformInfo` Formatter timeout debug
## NAVIGATE
### Windows, splits & tabs
- `Ctrl`+`wq` close window
- `Ctrl`+`ws` split window _horizontally_
- `Ctrl`+`wv` split window _vertically_
- `Ctrl`+`h/j/k/l` move between splits
- `Ctrl`+`w=` equalize split window width and height
- `Ctrl`+`wr` swap position of two windows
- `Ctrl`+`wT` move focused split to new tab
- `gt` or `gT` switch forward/reverse between tabs
### Buffers
- `leader`+`leader` lists open buffers [`snipe.nvim`]
- `:bd` close current buffer
### Text
- `w/e` move to _start_/_end_ of _next_ word
- `b` move to _start_ of _previous_ word
- `Ctrl`+`0` _start_ of line
- `Ctrl`+`$` _end_ of line
- `Ctrl`+`d/u` scroll _down_/_up_ 1/2 page keeping the cursor centered
- `Ctrl`+`o` jump to previous location (e.g. after using `gg`)
- `Ctrl`+`i` jump forward (after using `Ctrl`+`o`)
- `s<chars>` highlight jump targets [`flash.nvim`]
### LSP, Code & Diagnostics
- `Ctrl`+`j/k` scroll down/up through LSP suggestions
- `K` show LSP context info
- `Ctrl`+`o` show LSP completion menu in insert mode
- `gd` go to definition
- `gr` show references of function
- `grn` renames all refs of the symbol under cursor
- `leader`+`q` toggle `trouble.nvim`
- `leader`+`da` go to next diagnostic (any severity)
- `leader`+`dw` go to next diagnostic (_warning_ severity)
- `leader`+`de` go to next diagnostic (_error_ severity)
### Telescope
- `Esc`+`j/k` scroll down/up
- `Ctrl`+`d/u` scroll down/up in preview pane
- `Ctrl`+`v` open file in _vertical_ split
- `Ctrl`+`x` open file in _horizontal_ split
- `Ctrl`+`t` open file in new tab
### Oil
- `Ctrl`+`d/u` bottom/top of file list
- `Ctrl`+`p` preview file
- `Ctrl`+`v` open file in _vertical_ split
- `Ctrl`+`x` open file in _horizontal_ split
- `Ctrl`+`t` open file in new tab
### Snipe
- `D` close selected buffer
## SELECT, DELETE AND CHANGE TEXT
Prefix the marked commands below with `v` to select, `d` for deleting or `c` to
change.
- `leader`+`o` re-format whole file or visual [`conform.nvim`]
- `i/I` insert mode at _cursor position_/_beginning of the line_
- `a/A` insert mode _after the current char_/_at end of line_
- `o/O` insert mode a line _below_/_above_ the cursor
- `cc/S` replace _whole_ line
- `C` _replace_ to the _end_ of the line _from current position_
- `D` _delete_ to the end of the line
- `p/P` paste yanked line below/above
- `yygccp` comment and copy the current line
- `<prefix>$` ... to the end of the _line_
- `<prefix>w` ... to the end of current _word_
- `<prefix>ap` ... around _paragraph_
- `<prefix>ip` ... inside _paragraph_
- `<prefix>at` ... around HTML/XML _tag_
- `<prefix>it` ... inside HTML/XML _tag_
- `<prefix>iq` ... inside _quotes_ [`mini.ai`]
- `<prefix>aq` ... around _quotes_ [`mini.ai`]
- `<prefix>aW` ... word with dashes or underscores
### Selection-only commands
- `ViB` Select lines inside block (useful for commenting)
- `Ctrl`+`s` context-sensitive text selection (Tree-sitter)
- `Backspace` reduce context-sensitive selection
## GIT
- `:windo diffthis` open `vimdiff` for open splits
- `:vert diffsplit <other/file>` diff this file and `<other/file>`
- `:windo diffoff` to close diff view
## SEARCH/OPEN
- `leader`+`fg` search text in files (also searches for text under cursor)
- `leader`+`ff` search files (respects `.gitignore`)
- `leader`+`e` toggle Oil file explorer
- `leader`+`fo` recently opened files
- `gf` open file under cursor in a new buffer
- `gx` open link under cursor in default browser
- `*` search word under cursor
- `Ctrl`+`l` remove search highlight