neovim/CHEATSHEET.md

3.8 KiB

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