Skip to content

Neovim

Neovim is a powerful and highly customizable text editor that supports a wide range of programming languages.

Jump Commands

  • gg - Jump to first line
  • G - Jump to last line
  • {number}G - Jump to line number
  • 0 - Jump to start of line
  • $ - Jump to end of line
  • ^ - Jump to first non-blank character
  • w - Jump to start of next word
  • b - Jump to start of previous word
  • e - Jump to end of word
  • % - Jump to matching parenthesis/bracket
  • H - Jump to top of screen
  • M - Jump to middle of screen
  • L - Jump to bottom of screen
  • Ctrl-u - Move up half a screen
  • Ctrl-d - Move down half a screen
  • Ctrl-f - Page down
  • Ctrl-b - Page up
  • zz - Centre current line on screen
  • zt - Current line to top of screen
  • zb - 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 position
  • Ctrl-i - Jump forward to next position
  • :jumps - Display jump list

Text Objects and Operators

Text Objects

  • iw - Inner word
  • aw - Around word (includes surrounding space)
  • is - Inner sentence
  • as - Around sentence
  • ip - Inner paragraph
  • ap - Around paragraph
  • i( or i) - Inside parentheses
  • a( or a) - Around parentheses (includes parentheses)
  • i{ or i} - Inside curly braces
  • a{ or a} - Around curly braces
  • i[ or i] - Inside square brackets
  • a[ or a] - Around square brackets
  • i< or i> - Inside angle brackets
  • a< or a> - Around angle brackets
  • i" - Inside double quotes
  • a" - Around double quotes
  • i' - Inside single quotes
  • a' - Around single quotes
  • `i“ - Inside backticks
  • `a“ - Around backticks
  • it - Inside HTML/XML tag
  • at - Around HTML/XML tag

Operators (combine with text objects)

  • d - Delete
  • c - Change (delete and enter insert mode)
  • y - Yank (copy)
  • v - Visually select
  • > - Indent right
  • < - Indent left
  • = - Auto-indent
  • gq - Format text
  • gU - Convert to uppercase
  • gu - Convert to lowercase
  • g~ - Swap case
  • ! - Filter through external command

Operator Examples

  • diw - Delete inner word
  • ci" - Change text inside quotes
  • ya} - Yank text including curly braces
  • >ip - Indent paragraph
  • gUaw - Convert word to uppercase

Macros & Registers

Registers

  • "{a-z} - Named registers
  • "{A-Z} - Append to named registers
  • "0 - Yank register (last yanked text)
  • "1 to "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 register
  • Ctrl-r {reg} - Insert register contents in insert mode

Macros

  • q{a-z} - Record macro into register
  • q - Stop recording
  • @{a-z} - Execute macro from register
  • @@ - Repeat last executed macro
  • {number}@{a-z} - Execute macro multiple times

Advanced Search & Replace

  • /pattern - Search forward for pattern
  • ?pattern - Search backward for pattern
  • * - Search forward for word under cursor
  • # - Search backward for word under cursor
  • gd - Go to local definition of word under cursor
  • gD - Go to global definition of word under cursor
  • n - Repeat search in same direction
  • N - 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 line
  • c - Confirm each substitution
  • i - Case insensitive
  • I - Case sensitive
  • n - 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 vertically
  • Ctrl-w s - Split horizontally
  • Ctrl-w v - Split vertically
  • Ctrl-w q - Close window
  • Ctrl-w o - Close all windows except current
  • Ctrl-w h/j/k/l - Navigate between windows
  • Ctrl-w H/J/K/L - Move window
  • Ctrl-w = - Equal size windows
  • Ctrl-w _ - Maximize height
  • Ctrl-w | - Maximize width
  • Ctrl-w + - Increase height
  • Ctrl-w - - Decrease height
  • Ctrl-w > - Increase width
  • Ctrl-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 tabs
  • gt - Go to next tab
  • gT - 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 fold
  • za - Toggle fold
  • zo - Open fold
  • zc - Close fold
  • zR - Open all folds
  • zM - Close all folds
  • zj - Move to next fold
  • zk - 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 mode
  • I - Insert at start of selection
  • A - Append at end of selection
  • c - Change selection
  • r - Replace selection
  • d - Delete selection
  • o - Move to other corner of block
  • O - Move to other corner horizontally

Multiple Cursors (via block mode)

  1. Ctrl-v to enter visual block mode
  2. Select lines (j/k)
  3. Select columns (h/l)
  4. I to insert at start or A to append at end
  5. Type text
  6. 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

  • :terminal or :term - Open terminal
  • i - 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 definition
  • gr - Go to references
  • gi - 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.lua
local 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,
})
end
vim.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 settings
vim.opt.number = true -- Show line numbers
vim.opt.relativenumber = true -- Show relative line numbers
vim.opt.tabstop = 2 -- Tabs are 2 spaces
vim.opt.shiftwidth = 2 -- Indentation is 2 spaces
vim.opt.expandtab = true -- Use spaces instead of tabs
vim.opt.smartindent = true -- Smart auto indenting
vim.opt.wrap = false -- Don't wrap lines
vim.opt.ignorecase = true -- Ignore case in search
vim.opt.smartcase = true -- Override ignorecase if search has uppercase
vim.opt.hlsearch = true -- Highlight search results
vim.opt.incsearch = true -- Show matches as you type
vim.opt.hidden = true -- Allow switching buffers without saving
vim.opt.cursorline = true -- Highlight current line
vim.opt.splitright = true -- vsplit opens to the right
vim.opt.splitbelow = true -- hsplit opens below
vim.opt.termguicolors = true -- True color support
vim.opt.scrolloff = 8 -- Keep 8 lines above/below cursor
vim.opt.sidescrolloff = 8 -- Keep 8 columns left/right of cursor
vim.opt.undofile = true -- Persistent undo
vim.opt.backup = false -- No backup files
vim.opt.writebackup = false -- No backup files during write
vim.opt.showmode = false -- Don't show mode (for statusline plugins)
vim.opt.completeopt = { "menuone", "noselect" } -- Better completion experience
-- Key mappings
vim.g.mapleader = " " -- Set leader key to space
-- Quick save
vim.keymap.set('n', '<leader>w', ':w<CR>')
-- Quick quit
vim.keymap.set('n', '<leader>q', ':q<CR>')
-- Quick buffer navigation
vim.keymap.set('n', '<leader>bn', ':bnext<CR>')
vim.keymap.set('n', '<leader>bp', ':bprevious<CR>')
-- Clear search highlight with ESC
vim.keymap.set('n', '<Esc>', ':noh<CR><Esc>')
-- Move lines up/down in visual mode
vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")
vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")
-- Open file explorer
vim.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 explorer
  • a - Create file/directory
  • d - Delete file/directory
  • r - Rename file/directory
  • x - Cut file/directory
  • c - Copy file/directory
  • p - 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

  1. Use text objects - They’re powerful for quick edits
  2. Learn the dot command - . repeats the last change
  3. Use macros for repetitive tasks - Record complex sequences once
  4. Master search and replace - Especially with global commands
  5. Configure key mappings for common tasks - Save time and keystrokes
  6. Use registers effectively - Especially for copy/paste operations
  7. Learn Neovim’s built-in LSP capabilities - For better code navigation
  8. Use Lua for configuration - More powerful and faster than Vimscript
  9. Customize your config gradually - Don’t try to learn everything at once
  10. Watch for plugins that might slow down startup - Use lazy loading