Vim and Neovim Notes

Table of Contents

1. What is Vim/Neovim?

Vim stands for Vi IMproved. It is a modal text editor, which means you use different modes for moving, editing, selecting, and running commands.

Neovim is a modern fork of Vim with cleaner defaults, Lua configuration, built-in LSP support, and strong plugin support. If you are starting today, Neovim is usually the smoother daily editor, while basic Vim is still useful on servers.

Where Vim Helps

ReasonExplanation
Editing flowMove, change, delete, and repeat edits without leaving the keyboard.
UbiquityAvailable on every Unix system, SSH servers, containers
EfficiencyUseful for config files, logs, scripts, and remote troubleshooting.
ExtensibilityPlugins can turn Neovim into a focused coding environment.
PortabilityYour config travels with you
The Vim approach

Vim commands combine like a small editing language. For example, d means delete and w means word, so dw deletes a word. Once that idea clicks, the command list starts to feel less random.


2. Which One Should You Use?

FeatureVimNeovim
ConfigurationVimscript (.vimrc)Lua or Vimscript (init.lua)
LSP SupportVia plugins (CoC)Built-in native LSP
Async PluginsLimitedNative async support
Modern FeaturesClassicFloating windows, tree-sitter
Plugin EcosystemMatureGrowing rapidly
Default SettingsMinimalSensible defaults
Recommendation

Beginners: Start with Neovim if you want a modern editor for daily work.
Servers and SSH: Learn basic Vim because it is often available by default when you are editing config files remotely.


3. Installation Guide

Linux

# Vim
sudo apt install vim          # Debian/Ubuntu
sudo pacman -S vim            # Arch
sudo dnf install vim          # Fedora

# Neovim
sudo apt install neovim
sudo pacman -S neovim
sudo dnf install neovim

macOS

brew install vim
brew install neovim

Windows

# Using Chocolatey
choco install vim
choco install neovim

# Using Scoop
scoop install vim
scoop install neovim

# Using winget
winget install vim.vim
winget install Neovim.Neovim

Verify Installation

vim --version
nvim --version

4. Understanding Modes: The Core Concept

Vim is a modal editor, which means different modes handle different tasks. Normal mode is for movement and commands, Insert mode is for typing, and Visual mode is for selecting text.

ModePurposeEnter WithExit With
NormalNavigation, commandsEscAlready there
InsertType texti, a, oEsc
VisualSelect textv, V, Ctrl+vEsc
CommandEx commands:Enter or Esc
ReplaceOverwrite textREsc
Beginner note

A common beginner mistake is staying in Insert mode. Normal mode is your home base. Get used to tapping Esc, or remap it to jk if that feels better.

Ways to Enter Insert Mode

KeyAction
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
oOpen new line below
OOpen new line above
sSubstitute character (delete & insert)
SSubstitute entire line

5. Basic Navigation

Character Movement

KeyActionMnemonic
hMove leftleft
jMove downdown (j hangs down)
kMove upup (k points up)
lMove rightright

Word Movement

KeyAction
wNext word (start)
WNext WORD (whitespace-separated)
eEnd of word
EEnd of WORD
bBack to start of word
BBack to start of WORD

Line Movement

KeyAction
0Start of line
^First non-blank character
$End of line
g_Last non-blank character

Screen Movement

KeyAction
ggGo to first line
GGo to last line
:nGo to line n
Ctrl+dScroll down half page
Ctrl+uScroll up half page
Ctrl+fScroll forward full page
Ctrl+bScroll backward full page
HTop of screen (High)
MMiddle of screen
LBottom of screen (Low)
zzCenter cursor on screen
Practice tip: use counts

Prefix any motion with a number: 5j = move 5 lines down, 3w = move 3 words forward, 10G = go to line 10.


6. Editing Basics

Delete Commands

CommandAction
xDelete character under cursor
XDelete character before cursor
ddDelete entire line
DDelete from cursor to end of line
dwDelete word
d$Delete to end of line
d0Delete to start of line
dGDelete to end of file
dggDelete to start of file

Change Commands

Change = Delete + Enter Insert mode

CommandAction
ccChange entire line
CChange from cursor to end of line
cwChange word
ciwChange inner word
ci"Change inside quotes
ci(Change inside parentheses

Copy (Yank) and Paste

CommandAction
yyYank (copy) line
YYank line (same as yy)
ywYank word
y$Yank to end of line
pPaste after cursor
PPaste before cursor

Undo and Redo

CommandAction
uUndo
Ctrl+rRedo
UUndo all changes on line
.Repeat last command (useful)
The dot command repeats the last change

The . command repeats your last change. Example: ciwhelloEsc then navigate to another word and press . to replace it with "hello" too.


7. Advanced Motions and Text Objects

The Vim Grammar

Operator + Motion = Action

# Operators
d = delete
c = change
y = yank (copy)
v = visual select
> = indent right
< = indent left

# Formula: operator + [count] + motion
d2w   = delete 2 words
c3j   = change 3 lines down
y5l   = yank 5 characters right

Text Objects: a useful pattern

Text objects let you operate on semantic units of text.

ObjectMeaningExample
iwinner worddiw = delete word
awa word (includes space)daw = delete word + space
isinner sentencecis = change sentence
ipinner paragraphyip = yank paragraph
i"inside quotesci" = change inside quotes
a"around quotesda" = delete including quotes
i(inside parenthesesdi( = delete inside parens
i{inside curly bracesci{ = change inside braces
i[inside bracketsyi[ = yank inside brackets
itinside HTML tagcit = change tag content
ataround HTML tagdat = delete entire tag
Text objects reduce repeated movement

Instead of moving character by character, use ci" anywhere inside quotes to change that quoted text. dap deletes a whole paragraph. These are small commands, but they remove a lot of repeated movement.

Find and Till Motions

CommandAction
f{char}Jump to next {char} on line
F{char}Jump to previous {char}
t{char}Jump till (before) next {char}
T{char}Jump till previous {char}
;Repeat last f/t motion
,Repeat f/t in reverse direction
# Delete until comma
dt,

# Change to next quote
ct"

# Delete including the comma
df,

8. Search and Replace

Basic Search

CommandAction
/patternSearch forward
?patternSearch backward
nNext match
NPrevious match
*Search word under cursor (forward)
#Search word under cursor (backward)

Search and Replace (Substitute)

# Basic syntax
:s/old/new/           # Replace first on current line
:s/old/new/g          # Replace all on current line
:%s/old/new/g         # Replace all in file
:%s/old/new/gc        # Replace all with confirmation

# Case insensitive
:%s/old/new/gi

# Replace in range (lines 5-20)
:5,20s/old/new/g

# Replace in visual selection
:'<,'>s/old/new/g

Useful Search Patterns

# Word boundaries
/\             # Exact word match

# Case insensitive
/pattern\c

# Very magic mode (better regex)
/\v(pattern1|pattern2)
Clear search highlight

After searching, clear the highlight with :noh or :nohlsearch. If you search often, map this to a key like <leader>h.


9. Visual Mode

Visual Mode Types

KeyModeUse Case
vCharacter-wiseSelect characters
VLine-wiseSelect entire lines
Ctrl+vBlock (column)Select columns/rectangles

Visual Mode Operations

# Select and operate
v + motion + operator
viw + y              # Select inner word, yank
V5j + d              # Select 5 lines, delete

# Block mode magic (Ctrl+v)
Ctrl+v + 3j + I + // + Esc   # Comment 4 lines
Ctrl+v + 3j + $ + A + ; + Esc  # Add semicolon to 4 lines
Block mode for column edits

Ctrl+v lets you edit multiple lines at once. Select a column, press I to insert, type text, press Esc - text appears on all selected lines.

Useful Visual Commands

CommandAction
oMove to other end of selection
OMove to other corner (block mode)
gvReselect last visual selection
>Indent selection
<Unindent selection
=Auto-indent selection
~Toggle case
UUppercase
uLowercase

10. Registers and Advanced Yanking

Vim has multiple "clipboards" called registers.

Register Types

RegisterDescription
"Default (unnamed) register
0Yank register (last yanked text)
1-9Delete history (1 = most recent)
a-zNamed registers (you control)
A-ZAppend to named register
+System clipboard
*Primary selection (X11)
_Black hole (delete without saving)
/Last search pattern

Using Registers

# View all registers
:registers
:reg

# Yank to register a
"ayy

# Paste from register a
"ap

# Yank to system clipboard
"+yy

# Paste from system clipboard
"+p

# Delete without affecting registers
"_dd
The 0 Register Trick

When you yank text, it goes to register 0. When you delete, it goes to ". Use "0p to paste your last yank even after deleting!


11. Macros - Record & Replay

Macros record keystrokes and replay them. This is useful when the same edit repeats across many lines.

Basic Macro Workflow

# 1. Start recording to register q
qq

# 2. Perform your actions
...edit commands...

# 3. Stop recording
q

# 4. Replay macro
@q

# 5. Replay again
@@

# 6. Replay 10 times
10@q

Macro Example: Add Semicolons

# Starting position: cursor on first line
qq          # Start recording
A;          # Go to end, insert semicolon
Esc         # Exit insert mode
j           # Move to next line
q           # Stop recording

99@q        # Apply to next 99 lines
Macro practice tips

1. Start macros at line beginning (0) or on a word (b)
2. Use /pattern<CR> to jump consistently
3. End with motion to next target for chaining
4. Save macros in your vimrc: let @q = 'A;^[j'


12. Buffers, Windows and Tabs

Buffers (Open Files)

# List buffers
:ls
:buffers

# Switch buffers
:b [number]     # Go to buffer number
:b [name]       # Go to buffer by name
:bn             # Next buffer
:bp             # Previous buffer
:bd             # Delete (close) buffer

# Open file in new buffer
:e filename

Windows (Splits)

# Split windows
:sp [file]      # Horizontal split
:vsp [file]     # Vertical split
Ctrl+w s        # Horizontal split
Ctrl+w v        # Vertical split

# Navigate windows
Ctrl+w h        # Move left
Ctrl+w j        # Move down
Ctrl+w k        # Move up
Ctrl+w l        # Move right
Ctrl+w w        # Cycle windows

# Resize
Ctrl+w =        # Equal size
Ctrl+w >        # Wider
Ctrl+w <        # Narrower
Ctrl+w +        # Taller
Ctrl+w -        # Shorter

# Close
:q              # Close window
:only           # Close all other windows

Tabs

:tabnew [file]  # New tab
:tabn           # Next tab
:tabp           # Previous tab
gt              # Next tab
gT              # Previous tab
:tabclose       # Close tab

13. Configuration

Config File Locations

# Vim
~/.vimrc                    # Linux/Mac
~/_vimrc                    # Windows

# Neovim
~/.config/nvim/init.vim     # Vimscript
~/.config/nvim/init.lua     # Lua (recommended)

Essential .vimrc Settings

" Basic settings
set nocompatible
set number relativenumber   " Line numbers
set tabstop=4               " Tab width
set shiftwidth=4            " Indent width
set expandtab               " Spaces instead of tabs
set autoindent              " Auto indent
set smartindent             " Smart indent
set wrap                    " Wrap lines
set linebreak               " Wrap at word boundaries

" Search
set ignorecase              " Case insensitive
set smartcase               " Unless uppercase used
set hlsearch                " Highlight matches
set incsearch               " Incremental search

" UI
set cursorline              " Highlight current line
set showmatch               " Show matching brackets
set wildmenu                " Command completion
set scrolloff=8             " Keep 8 lines visible
set signcolumn=yes          " Always show sign column
set colorcolumn=80          " Show column marker

" Performance
set lazyredraw              " Don't redraw during macros
set updatetime=300          " Faster updates

" Key mappings
let mapleader = " "         " Space as leader
inoremap jk <Esc>           " jk to escape
nnoremap <leader>w :w<CR>   " Quick save
nnoremap <leader>h :noh<CR> " Clear search

Neovim init.lua Basics

-- Basic options
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.cursorline = true
vim.opt.ignorecase = true
vim.opt.smartcase = true

-- Leader key
vim.g.mapleader = " "

-- Key mappings
vim.keymap.set('i', 'jk', '<Esc>')
vim.keymap.set('n', '<leader>w', ':w<CR>')
vim.keymap.set('n', '<leader>h', ':noh<CR>')

14. Essential Plugins

Plugin Managers

ManagerFor
vim-plugVim & Neovim
packer.nvimNeovim (Lua)
lazy.nvimNeovim (modern, recommended)

Useful Plugins

PluginPurpose
nvim-treesitterBetter syntax highlighting
nvim-lspconfigLanguage Server Protocol
telescope.nvimFuzzy finder (files, grep, etc.)
nvim-cmpAutocompletion
nvim-tree / neo-treeFile explorer
lualine.nvimStatus line
gitsigns.nvimGit integration
vim-surroundSurround text objects
comment.nvimEasy commenting
which-key.nvimKeybinding hints
Starter configs

You do not have to build from scratch. Try these preconfigured Neovim distros:
- LazyVim - Modern, fast, well-maintained
- NvChad - Beautiful, beginner-friendly
- AstroNvim - Feature-rich, extensible
- LunarVim - IDE-like experience


15. Practical Editing Habits

Editing habits

  1. Stay in Normal mode - Make the edit, then return to Normal mode.
  2. Think in text objects - Use commands like ciw, dap, and yi" instead of selecting manually
  3. Use counts - Try 5dd, 3yy, or 10j when you need repetition
  4. Use the dot command - Repeat the last change with .
  5. Use macros for repetition - Record once, replay when the same edit repeats

Practice techniques

1. Replace Escape with jk

inoremap jk <Esc>

This keeps the escape action close to the home row.

2. Use Leader for Common Actions

let mapleader = " "
nnoremap <leader>w :w<CR>     " Save
nnoremap <leader>q :q<CR>     " Quit
nnoremap <leader>e :Ex<CR>    " File explorer

3. Jump Instead of Scrolling

/ and ?        # Search to jump
*              # Jump to word under cursor
f and t        # Line-level precision
{  }           # Jump paragraphs
]]  [[         # Jump sections/functions
gd             # Go to definition
Ctrl+o Ctrl+i  # Jump list back/forward

4. Use Marks for Quick Navigation

ma             # Set mark 'a' at cursor
'a             # Jump to line of mark 'a'
`a             # Jump to exact position of mark 'a'
''             # Jump to last position
'.             # Jump to last edit

5. Master ciw, ci", ci(

These commands are worth practicing first:

ciw    # Change word (anywhere in word)
ci"    # Change inside quotes
ci(    # Change inside parentheses
ci{    # Change inside braces
cit    # Change inside HTML tag

6. Quick Fixes

~      # Toggle case of character
xp     # Swap two characters
ddp    # Swap two lines
J      # Join lines
gU{motion}  # Uppercase
gu{motion}  # Lowercase

7. Global Commands

:g/pattern/d       # Delete all lines matching pattern
:g!/pattern/d      # Delete lines NOT matching
:g/pattern/normal A;  # Append ; to matching lines
A practical learning order

Level 1: hjkl instead of arrows
Level 2: word motions (w, b, e)
Level 3: text objects (ciw, ci", dap)
Level 4: search/find motions (/, f, t)
Level 5: marks and jumps
Level 6: macros and global commands
Final step: Thinking in Vim grammar


16. Practice Exercises

Beginner Exercises

Exercise 1: Basic Navigation

Open a file with 50+ lines. Navigate using only hjkl for 5 minutes. Use hjkl only for this drill.

Goal: Build muscle memory for basic movement.

Exercise 2: Word Jumps

Move through a paragraph using only w, b, and e. Count how many keystrokes to get from start to end.

Exercise 3: Delete Practice

Create lines of text. Practice: dd, 3dd, dw, d$, d0

Intermediate Exercises

Exercise 4: Text Objects

Given: const name = "John Doe";
Change "John Doe" to "Jane Smith" using only ci"

Exercise 5: Function Editing

Given a function with content in curly braces:
function test() { old content here }
Replace all content inside {} using ci{

Exercise 6: Search and Replace

Replace all occurrences of "foo" with "bar" in a file.

:%s/foo/bar/g
Exercise 7: Visual Block

Add // comment prefix to 10 consecutive lines using Ctrl+v

Ctrl+v -> 9j -> I -> // -> Esc

Advanced Exercises

Exercise 8: Macro Challenge

You have 20 lines like: item1, item2...
Convert all to: - [ ] item1
Record macro, apply to all lines.

qq0i- [ ] <Esc>jq
19@q
Exercise 9: Registers

Yank a line to register "a", yank another to "b". Paste both in different locations.

"ayy    # Yank to a
"byy    # Yank to b
"ap     # Paste from a
"bp     # Paste from b
Exercise 10: The Dot Command

Change "old" to "new" on 5 different lines using ciw once, then n. for others.

/old<CR>   # Find first
ciwnew<Esc> # Change it
n.         # Find next, repeat change
n.         # Repeat...

Practice Resources


17. Quick Reference

Survival Kit

CommandAction
:wSave
:qQuit
:wqSave and quit
:q!Quit without saving
uUndo
Ctrl+rRedo
EscReturn to Normal mode

Movement

CommandAction
hjklLeft/Down/Up/Right
w / bNext/Previous word
0 / $Start/End of line
gg / GStart/End of file
Ctrl+d / Ctrl+uHalf page down/up
f{char} / t{char}Find/Till character

Editing

CommandAction
i / aInsert before/after cursor
o / ONew line below/above
dd / yy / pDelete/Yank/Paste line
ciw / diwChange/Delete inner word
ci" / di"Change/Delete inside quotes
.Repeat last change

Search

CommandAction
/patternSearch forward
n / NNext/Previous match
*Search word under cursor
:%s/old/new/gReplace all

Windows

CommandAction
:sp / :vspHorizontal/Vertical split
Ctrl+w hjklNavigate splits
Ctrl+w qClose split
Remember

Vim practice takes time. Learn one small command, use it for real edits, and let the habit build slowly. The goal is not to memorize everything at once.


Keep practicing. The goal is controlled, confident editing, not memorizing every command at once.