Neovim Cheatsheet: The Complete Guide to Mastering Neovim Commands

Learn the essential Neovim commands and shortcuts with this categorized cheatsheet designed for maximum productivity in coding and text editing.

General Commands

File Management

:e filename          " Open a file
:w                   " Save the current file
:q                   " Quit Neovim
:wq                  " Save and quit
:x                   " Shortcut for :wq
:qa                  " Quit all files
:wa                  " Save all open files

Buffers

:bnext       " Go to the next buffer
:bprev       " Go to the previous buffer
:bd          " Close the current buffer
:ls          " List all buffers
:buffer N    " Switch to buffer N

Windows (Splits)

:split        " Horizontal split
:vsplit       " Vertical split
Ctrl-w w      " Switch between windows
Ctrl-w h/j/k/l " Navigate windows
Ctrl-w q      " Close the current window
Ctrl-w =      " Equalize window sizes

Editing

Modes

i    " Insert mode
a    " Append after cursor
I    " Insert at the beginning of the line
A    " Append at the end of the line
Esc  " Return to normal mode

Text Manipulation

dd    " Delete a line
yy    " Copy a line
p     " Paste below the current line
P     " Paste above the current line
x     " Delete a character
u     " Undo the last change
Ctrl-r " Redo the last undo

Indentation

>>    " Indent the current line
<<    " Un-indent the current line
=     " Auto-indent a line or selection

By Character/Word

h   " Move left
l   " Move right
w   " Jump to the start of the next word
e   " Jump to the end of the current/next word
b   " Jump to the beginning of the previous word

By Line

0   " Jump to the beginning of the line
^   " Jump to the first non-whitespace character
$   " Jump to the end of the line

By Paragraph

{   " Jump to the beginning of the previous paragraph
}   " Jump to the beginning of the next paragraph

By Screen

Ctrl-d " Scroll down half a screen
Ctrl-u " Scroll up half a screen
Ctrl-f " Scroll down a full screen
Ctrl-b " Scroll up a full screen

Visual Mode

Mode

v       " Enter visual mode
V       " Enter line visual mode
Ctrl-v  " Enter block visual mode
o       " Switch to the other end of the selection

Command Mode

Searching and Replacing

:s/old/new/      " Replace the first occurrence of 'old' with 'new' in the current line
:s/old/new/g     " Replace all occurrences in the current line
:%s/old/new/g    " Replace all occurrences in the entire file
:%s/old/new/gc   " Replace with confirmation

Exiting

:w   " Save the file
:q   " Quit
:wq  " Save and quit
:q!  " Quit without saving

Plugins

Plugin Manager (Packer Example)

:PackerInstall   " Install plugins
:PackerUpdate    " Update plugins
:PackerClean     " Remove unused plugins
:PackerSync      " Install, update, and clean plugins

Telescope (File Navigation)

:Telescope find_files   " Find files
:Telescope live_grep    " Search within files
:Telescope buffers      " List open buffers

Nvim-tree (File Explorer)

<leader>e       " Toggle the file explorer

Key Bindings

Customization Examples

nnoremap key command    " Map a key in normal mode
inoremap key command    " Map a key in insert mode
vnoremap key command    " Map a key in visual mode

Configuration

init.vim (Vimscript)

set number          " Show line numbers
syntax on           " Enable syntax highlighting
set expandtab       " Use spaces instead of tabs
set tabstop=4       " Set tab width to 4 spaces
set shiftwidth=4    " Set indentation width to 4 spaces

init.lua (Lua)

vim.o.number = true         -- Show line numbers
vim.cmd('syntax on')        -- Enable syntax highlighting
vim.o.expandtab = true      -- Use spaces instead of tabs
vim.o.tabstop = 4           -- Set tab width to 4 spaces
vim.o.shiftwidth = 4        -- Set indentation width to 4 spaces

Additional Resources and References