Skip to content
kamack38 edited this page Mar 13, 2025 · 32 revisions

Neovim Cheatsheet

  • :w ++p - to save a file and create all necessary directories
  • :f ./newfile - copy currently opened file and give it a new name
  • :e %:h/file - edit a file relative to the currently opened buffer parent directory
  • :reg - show contents of the registers
  • :%! - filter the entire buffer through an external command
  • gp - selects the pasted text (custom)
  • gv - reselects the last selection
  • ga - information about a character under cursor
  • gU{motion} - convert to uppercase
  • gu{motion} - convert to lowercase
  • <C-u> - (insert mode) delete till the start of the line
  • <C-a> - increment number
  • <C-x> - decrement number
  • <C-g> - print full file path
  • o - jump between the start and the end of a visual selection
  • q{A-Z} - append to a macro
  • * - searches forward for the word nearest to the cursor

Marks (via yehuohan/marks.nvim)

  • mx - toggle mark 'x' and display it in the leftmost column
  • m, - set the next available alphabetical (lowercase) mark
  • m; - toggle the next available mark at the current line
  • dmx - remove mark 'x'
  • dm- - delete all marks on the current line
  • dm<Space> - delete all marks in the current buffer
  • ]`, m] - jump to next mark
  • [`, m[ - jump to previous mark
  • m[0-9] - set bookmark from group 0-9
  • dm[0-9] - remove all bookmarks from group 0-9
  • m} - move to the next bookmark having the same type as the bookmark under the cursor
  • m{ - move to the previous bookmark having the same type as the bookmark under the cursor

Surround (via nvim-surround)

  • ys{motion}{char} - surrounds a {motion} with a {char}
  • ds{char} - delete a {char} surround
  • cs{char1}{char2} - changes a {char1} surround to {char2}

Examples

Old text Command New text
surr*ound_words ysiw) (surround_words)
*make strings ys$" "make strings"
[delete ar*ound me!] ds] delete around me!
remove <b>HTML t*ags</b> dst remove HTML tags
'change quot*es' cs'" "change quotes"
<b>or tag* types</b> csth1<CR> <h1>or tag types</h1>
delete(functi*on calls) dsf function calls

Motions

  • gj - go one visual line down
  • gk - go one visual line up
  • gm - go to the middle of the screen

Line motions

  • D delete till the end of line
  • C change till the end of line
  • Y yank till the end of line
  • S replace the whole line

Objects

  • w - a word
  • W - a WORD
  • s - a sentence
  • p - a paragraph
  • t - a <tag>
  • []/<> - a []/<> block
  • ()/b - a () block
  • {}/B - a {} block

Modifiers

  • i - inner
  • a - "a" (around)

All text objects

Additional text objects (via nvim-various-textobjs)

textobject description inner / outer keymaps filetypes (for default keymaps)
indentation lines with same or higher indentation ii, ai, aI, (iI) all
restOfIndentation lines down with same or higher indentation - R all
greedyOuterIndentation outer indentation, expanded to blank lines; useful to get functions with annotations o: a blank, like ap/ip ag/ig all
subword like iw, but treating - and _ as word delimiters and only part of camelCase o: trailing _,-, or space iS/aS all
toNextClosingBracket from cursor to next closing ], ), or } - C all
toNextQuotationMark from cursor to next unescaped[^1] ", ', or ` - Q all
anyQuote between any unescaped[^1] ", ', or ` in a line o: quotation marks iq/aq all
anyBracket between any (), [], or {} in a line o: brackets io/ao all
restOfParagraph like }, but linewise - r all
entireBuffer entire buffer as one text object - gG all
nearEoL from cursor position to end of line, minus one character - n all
lineCharacterwise current line, but characterwise o: indentation and trailing spaces i_/a_ all
column column down until indent or shorter line. Accepts {count} for multiple columns. - | all
value value of key-value pair, or right side of a assignment, excl. trailing comment (in a line) o: trailing commas or semicolons iv/av all
key key of key-value pair, or left side of a assignment o: includes the = or : ik/ak all
url works with http[s] or any other protocol - L all
number numbers, similar to <C-a> i: digits, o: including -, , and . in/an all
diagnostic LSP diagnostic (requires built-in LSP) - ! all
closedFold closed fold o: one line after the last folded line iz/az all
chainMember field with optional call, like .foo(param) or .bar o: leading . (or :) im/am all
visibleInWindow all lines visible in the current window - gw all
restOfWindow from the cursorline to the last line in the window - gW all
lastChange Last non-deletion-change, yank, or paste.[^2] - g; all
mdlink markdown link like [title](url) i: only the link title ([]) il/al markdown, toml
mdEmphasis markdown text enclosed by *, **, _, __, ~~, or == i: only the emphasis content ie/ae markdown
mdFencedCodeBlock markdown fenced code (enclosed by three backticks) o: enclosing backticks iC/aC markdown
cssSelector class in CSS like .my-class o: trailing comma and space ic/ac css, scss
cssColor color in CSS (hex, rgb, or hsl) i: only the color value i#/a# css, scss
htmlAttribute attribute in html/xml like href="foobar.com" i: is only the value inside the quotes ix/ax html, xml, css, scss, vue
doubleSquareBrackets text enclosed by [[]] o: includes the four square brackets iD/aD lua, shell, neorg, markdown
shellPipe segment until/after a pipe character (|) o: includes the pipe iP/aP bash, zsh, fish, sh
pyTripleQuotes python strings surrounded by three quotes (regular or f-string) i: excludes the """ or ''' iy/ay python
notebookCell cell delimited by [double percent comment][jupytext], such as # %% o: includes the bottom cell border iN/aN all

Jumping

  • ( and ) - moves between sentences
  • { and } - moves between paragraphs
  • [ and ] - jumps between objects
  • % - jumps between matching braces
  • <C-]>, K - jump to a tag
  • <C-o> - move backwards through the jump list
  • <C-i> - move forward through the jump list

Splits

  • <C-hjkl> - move between splits

  • <C-W> HJKL - move split

  • <C-W> = - make all splits equally high and wide

  • <C-W>[count]_ - set window height

  • <C-W>[count]+ - increase window height

  • <C-W>[count]- - decrease window height

  • <C-W>[count]| - set window width

  • <C-W>[count]> - increase window width

  • <C-W>[count]< - decrease window width

  • :vert[ical] {cmd} - Execute {cmd}. If it contains a command that splits a window, it will be split vertically. (Useful for vertical help)

See more All window commands

Tabs

  • :tabnew - create a new tab page with an empty window
  • gt - go to the next tab page.
  • gT - go to the previous tab page.

See more

Sessions

  • :mksession [file] - creates a session file
  • :source [file] - reads a session file
  • -S [file] - loads a session (cmdline option)
  • :wshada! [file] - writes to shada file
  • :rshada! [file] - reads from shada file
  • :mkview [file] - creates a view
  • :loadview [file] - loads a view

Regex

  • :g/pattern/d - remove lines matching pattern
  • :g!/pattern/d - remove lines that do NOT match
  • .\{-} - not greedy version of .*
  • & - inserts the matched text in a replacement pattern

Command-line

  • <C-b> - cursor to begin of command-line
  • <C-e> - cursor to end of command-line
  • <C-r>{register} - insert the contents of a numbered or named register
  • :!{cmd} - execute {cmd}
  • :r!{cmd} - execute {cmd} and insert its standard output below the cursor
  • '<,'>w !{cmd} - pass selection to {cmd} and print its output in viminfo

Ranges

  • :* - uses last visual area after visual mode has already ended

Repeats

  • . - repeats last change
  • ; - repeats latest f, t, F or T
  • , - repeats latest f, t, F or T in opposite direction
  • @: - repeats last command-line

See more

Tips

  • v<text-object><Esc> - to go to the text object
  • :verbose set <value>? - get which file changes a variable
  • :'<,'>t'a - to copy last selection under mark a
  • :s/someWord/\r/ - replace someWord with new line

All Neovim mappings