Neovim
Neovim is a powerful and highly customizable text editor that supports a wide range of programming languages.
Navigation & Movement
Jump Commands
gg- Jump to first lineG- Jump to last line{number}G- Jump to line number0- Jump to start of line$- Jump to end of line^- Jump to first non-blank characterw- Jump to start of next wordb- Jump to start of previous worde- Jump to end of word%- Jump to matching parenthesis/bracketH- Jump to top of screenM- Jump to middle of screenL- Jump to bottom of screenCtrl-u- Move up half a screenCtrl-d- Move down half a screenCtrl-f- Page downCtrl-b- Page upzz- Centre current line on screenzt- Current line to top of screenzb- Current line to bottom of screen
Marks
m{a-zA-Z}- Set mark at cursor position`{a-zA-Z}- Jump to mark`{0-9}- Jump to position before last exit`.- Jump to last change in current buffer`"- Jump to position when last editing file`^- Jump to position of last insertion`[- Jump to start of last change or yank`]- Jump to end of last change or yank
Jumps
Ctrl-o- Jump back to previous positionCtrl-i- Jump forward to next position:jumps- Display jump list
Text Objects and Operators
Text Objects
iw- Inner wordaw- Around word (includes surrounding space)is- Inner sentenceas- Around sentenceip- Inner paragraphap- Around paragraphi(ori)- Inside parenthesesa(ora)- Around parentheses (includes parentheses)i{ori}- Inside curly bracesa{ora}- Around curly bracesi[ori]- Inside square bracketsa[ora]- Around square bracketsi<ori>- Inside angle bracketsa<ora>- Around angle bracketsi"- Inside double quotesa"- Around double quotesi'- Inside single quotesa'- Around single quotes- `i“ - Inside backticks
- `a“ - Around backticks
it- Inside HTML/XML tagat- Around HTML/XML tag
Operators (combine with text objects)
d- Deletec- Change (delete and enter insert mode)y- Yank (copy)v- Visually select>- Indent right<- Indent left=- Auto-indentgq- Format textgU- Convert to uppercasegu- Convert to lowercaseg~- Swap case!- Filter through external command
Operator Examples
diw- Delete inner wordci"- Change text inside quotesya}- Yank text including curly braces>ip- Indent paragraphgUaw- Convert word to uppercase
Macros & Registers
Registers
"{a-z}- Named registers"{A-Z}- Append to named registers"0- Yank register (last yanked text)"1to"9- Numbered registers (historical delete/change)"+- System clipboard (X11 primary selection)"*- System clipboard (X11 clipboard)"_- Black hole register (discard)"%- Current file name".- Last inserted text":- Last command"/- Last search pattern:reg- Display registers and their contents
Register Usage
"{reg}y{motion}- Yank into register"{reg}p- Paste after cursor from register"{reg}P- Paste before cursor from registerCtrl-r {reg}- Insert register contents in insert mode
Macros
q{a-z}- Record macro into registerq- Stop recording@{a-z}- Execute macro from register@@- Repeat last executed macro{number}@{a-z}- Execute macro multiple times
Advanced Search & Replace
Search
/pattern- Search forward for pattern?pattern- Search backward for pattern*- Search forward for word under cursor#- Search backward for word under cursorgd- Go to local definition of word under cursorgD- Go to global definition of word under cursorn- Repeat search in same directionN- Repeat search in opposite direction:noh- Clear search highlighting
Search Options
\c- Case insensitive search\C- Case sensitive search\v- Very magic mode (fewer escapes needed)\V- Very nomagic mode (only \ has special meaning)\<word\>- Match whole word
Search & Replace
:[range]s/pattern/replacement/[flags]- Substitute&- Repeat last substitute:&&- Repeat last substitute with same flags:%s/pattern/replacement/g- Replace all in file:'<,'>s/pattern/replacement/g- Replace in visual selection:.,+5s/pattern/replacement/g- Replace in current line and next 5 lines
Flags
g- Replace all occurrences in each linec- Confirm each substitutioni- Case insensitiveI- Case sensitiven- Show number of matches (don’t replace)
Global Command
:g/pattern/cmd- Execute cmd on lines matching pattern:v/pattern/cmd- Execute cmd on lines not matching pattern:g/pattern/d- Delete all lines containing pattern:v/pattern/d- Delete all lines not containing pattern
Advanced Editing
Multiple Windows
:sp [file]- Split horizontally:vsp [file]- Split verticallyCtrl-w s- Split horizontallyCtrl-w v- Split verticallyCtrl-w q- Close windowCtrl-w o- Close all windows except currentCtrl-w h/j/k/l- Navigate between windowsCtrl-w H/J/K/L- Move windowCtrl-w =- Equal size windowsCtrl-w _- Maximize heightCtrl-w |- Maximize widthCtrl-w +- Increase heightCtrl-w -- Decrease heightCtrl-w >- Increase widthCtrl-w <- Decrease width
Tabs
:tabnew [file]- Open file in new tab:tabe [file]- Open file in new tab:tabc- Close current tab:tabo- Close all other tabsgt- Go to next tabgT- Go to previous tab{number}gt- Go to specific tab number
Buffers
:ls- List buffers:b{number}- Go to buffer by number:bn- Go to next buffer:bp- Go to previous buffer:bd- Delete buffer:bufdo {cmd}- Execute command on all buffers:e {file}- Edit file in new buffer:sav {file}- Save file as and edit new copy
Folding
zf{motion}- Create foldza- Toggle foldzo- Open foldzc- Close foldzR- Open all foldszM- Close all foldszj- Move to next foldzk- Move to previous fold:set foldmethod=syntax- Fold based on syntax:set foldmethod=indent- Fold based on indent:set foldmethod=marker- Fold based on markers
Visual Block Mode
Ctrl-v- Enter visual block modeI- Insert at start of selectionA- Append at end of selectionc- Change selectionr- Replace selectiond- Delete selectiono- Move to other corner of blockO- Move to other corner horizontally
Multiple Cursors (via block mode)
Ctrl-vto enter visual block mode- Select lines (j/k)
- Select columns (h/l)
Ito insert at start orAto append at end- Type text
- Press
Esc
Command Line
:!{cmd}- Execute external command:r !{cmd}- Insert output of command:.!{cmd}- Filter current line through command:%!{cmd}- Filter entire file through command:w !{cmd}- Use buffer as input to command
Neovim-Specific Features
Built-in Terminal
:terminalor:term- Open terminali- Interact with terminal<C-\><C-n>- Exit terminal mode:split | terminal- Open terminal in split
LSP (Language Server Protocol)
Note: Requires configuration or plugins
gd- Go to definitiongr- Go to referencesgi- Go to implementation<C-k>- Show signature help:lua vim.lsp.buf.hover()- Show hover information:lua vim.lsp.buf.rename()- Rename symbol:lua vim.lsp.buf.format()- Format document
Built-in Lua Support
:lua print("Hello, Neovim!")- Execute Lua code:luafile ~/.config/nvim/script.lua- Run Lua file:source ~/.config/nvim/script.vim- Run Vimscript file
Plugin Management with Lazy.nvim
-- In init.lualocal lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"if not vim.loop.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath, })endvim.opt.rtp:prepend(lazypath)
require("lazy").setup({ -- Add your plugins here "neovim/nvim-lspconfig", "hrsh7th/nvim-cmp", "nvim-treesitter/nvim-treesitter",})Advanced .vimrc / init.lua Configuration
Lua Configuration Example
-- Basic settingsvim.opt.number = true -- Show line numbersvim.opt.relativenumber = true -- Show relative line numbersvim.opt.tabstop = 2 -- Tabs are 2 spacesvim.opt.shiftwidth = 2 -- Indentation is 2 spacesvim.opt.expandtab = true -- Use spaces instead of tabsvim.opt.smartindent = true -- Smart auto indentingvim.opt.wrap = false -- Don't wrap linesvim.opt.ignorecase = true -- Ignore case in searchvim.opt.smartcase = true -- Override ignorecase if search has uppercasevim.opt.hlsearch = true -- Highlight search resultsvim.opt.incsearch = true -- Show matches as you typevim.opt.hidden = true -- Allow switching buffers without savingvim.opt.cursorline = true -- Highlight current linevim.opt.splitright = true -- vsplit opens to the rightvim.opt.splitbelow = true -- hsplit opens belowvim.opt.termguicolors = true -- True color supportvim.opt.scrolloff = 8 -- Keep 8 lines above/below cursorvim.opt.sidescrolloff = 8 -- Keep 8 columns left/right of cursorvim.opt.undofile = true -- Persistent undovim.opt.backup = false -- No backup filesvim.opt.writebackup = false -- No backup files during writevim.opt.showmode = false -- Don't show mode (for statusline plugins)vim.opt.completeopt = { "menuone", "noselect" } -- Better completion experience
-- Key mappingsvim.g.mapleader = " " -- Set leader key to space
-- Quick savevim.keymap.set('n', '<leader>w', ':w<CR>')-- Quick quitvim.keymap.set('n', '<leader>q', ':q<CR>')-- Quick buffer navigationvim.keymap.set('n', '<leader>bn', ':bnext<CR>')vim.keymap.set('n', '<leader>bp', ':bprevious<CR>')-- Clear search highlight with ESCvim.keymap.set('n', '<Esc>', ':noh<CR><Esc>')-- Move lines up/down in visual modevim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")-- Open file explorervim.keymap.set('n', '<leader>e', ':Explore<CR>')Essential Plugins
- nvim-lspconfig - Configure Language Server Protocol
- nvim-cmp - Completion engine
- nvim-treesitter - Better syntax highlighting
- telescope.nvim - Fuzzy finder
- lazy.nvim - Plugin manager
- lualine.nvim - Status line
- which-key.nvim - Key binding hints
- nvim-tree.lua - File explorer
- gitsigns.nvim - Git integration
- null-ls.nvim - Formatting and linting
Plugin-Specific Commands
Telescope.nvim
<leader>ff- Find files<leader>fg- Live grep<leader>fb- Buffers<leader>fh- Help tags
nvim-tree.lua
<leader>e- Toggle file explorera- Create file/directoryd- Delete file/directoryr- Rename file/directoryx- Cut file/directoryc- Copy file/directoryp- Paste file/directory
Git (with gitsigns.nvim)
<leader>hs- Stage hunk<leader>hu- Undo hunk<leader>hr- Reset hunk<leader>hb- Blame line<leader>hp- Preview hunk<leader>hd- Diff this
Troubleshooting
Debugging
:checkhealth- Check Neovim health:messages- View message history:verbose map <key>- Check where key mapping is defined:verbose set {option}?- Check where option is set:scriptnames- List all loaded scripts
Performance Issues
:profile start profile.log- Start profiling:profile func *- Profile all functions:profile file *- Profile all files{do some actions}- Actions to profile:profile stop- Stop profiling
Tips for Efficiency
- Use text objects - They’re powerful for quick edits
- Learn the dot command -
.repeats the last change - Use macros for repetitive tasks - Record complex sequences once
- Master search and replace - Especially with global commands
- Configure key mappings for common tasks - Save time and keystrokes
- Use registers effectively - Especially for copy/paste operations
- Learn Neovim’s built-in LSP capabilities - For better code navigation
- Use Lua for configuration - More powerful and faster than Vimscript
- Customize your config gradually - Don’t try to learn everything at once
- Watch for plugins that might slow down startup - Use lazy loading
Recommended Learning Resources
:help- Neovim’s built-in documentation:Tutor- Interactive tutorial- Neovim Official Documentation
- Learn Vim the Hard Way
- ThePrimeagen’s YouTube Vim Tutorials
- TJ DeVries’ Neovim Videos