Vim Basics: Getting Started with the Terminal Editor
Vim is a modal text editor built for keyboard-only efficiency — once muscle memory forms, you’ll edit text faster than any mouse-driven editor, by keeping your fingers on the home row and using composable commands instead of menus and toolbars.
What You’ll Learn
- The four Vim modes: Normal, Insert, Visual, and Command-line
- Essential navigation with h/j/k/l, words, and line jumps
- Editing commands: delete, yank, paste, undo, replace
- Search, substitution, and global commands
- Basic .vimrc configuration and plugin management with vim-plug
Why Vim Basics Matter
Vim is installed on practically every Unix-like system. When you SSH into a server, edit a config file, or work on a remote machine, Vim is there. Even if your daily editor is VS Code, knowing Vim basics means you’re never helpless on a bare terminal.
Durga Antivirus Pro uses Vim for on-server configuration editing and quick log file analysis during incident response.
Learning Path
flowchart LR
A[Terminal Basics] --> B[Vim Modes<br/>You are here]
B --> C[Navigation & Editing]
C --> D[Search & Substitution]
D --> E[.vimrc & Plugins]
E --> F[Productive Vim Workflow]
style B fill:#f90,color:#fff
Understanding Vim Modes
Vim’s defining feature is modal editing — the keyboard does different things depending on the current mode.
| Mode | How to Enter | What It’s For |
|---|---|---|
| Normal | Esc | Navigation, copying, deleting, undoing |
| Insert | i, a, o | Typing text |
| Visual | v, V, Ctrl+v | Selecting text by character, line, or block |
| Command-line | : | Running commands like save, quit, search |
Most beginners get confused because they try to type while in Normal mode — the letters become commands, not text. Press i to enter Insert mode first.
Essential Navigation
Keep your hands on the home row. Never reach for arrow keys:
| Key | Movement |
|---|---|
h | Left one character |
j | Down one line |
k | Up one line |
l | Right one character |
w | Forward one word |
b | Backward one word |
e | End of current word |
0 | Beginning of line |
$ | End of line |
gg | First line of file |
G | Last line of file |
:42 | Go to line 42 |
Numbers prefix moves: 3w moves forward 3 words, 5j moves down 5 lines.
Editing Commands
| Command | Effect |
|---|---|
x | Delete character under cursor |
dd | Delete (cut) current line |
dw | Delete from cursor to end of word |
d$ | Delete from cursor to end of line |
yy | Yank (copy) current line |
p | Paste after cursor |
P | Paste before cursor |
u | Undo |
Ctrl+r | Redo |
. | Repeat last change |
r | Replace single character |
Combine commands with motions: d3w deletes three words, y2j yanks two lines (current and below).
Search and Substitution
/pattern " Search forward for 'pattern'
?pattern " Search backward
n " Repeat search forward
N " Repeat search backward
:%s/old/new/g " Replace all 'old' with 'new' in file
:%s/old/new/gc " Same, but ask for confirmation each time
:5,15s/old/new/g " Replace only between lines 5-15Example: Convert snake_case to camelCase
Before:
user_name, account_id, created_at
After running: :%s/_\(.\)/\U\1/g
userName, accountId, createdAtBasic .vimrc Configuration
Your .vimrc file (~/.vimrc) configures Vim’s behavior:
" Essential settings
set nocompatible
syntax on
filetype plugin indent on
set number
set relativenumber
set tabstop=2
set shiftwidth=2
set expandtab
set mouse=a
set clipboard=unnamedplus
set hlsearch
set incsearch
set ignorecase
set smartcase
" Leader key (space)
let mapleader = " "
" Quick save and quit
nnoremap <Leader>w :w<CR>
nnoremap <Leader>q :q<CR>
nnoremap <Leader>wq :wq<CR>
" Clear search highlight
nnoremap <Leader>h :nohlsearch<CR>
" Buffer navigation
nnoremap <Leader>n :bnext<CR>
nnoremap <Leader>p :bprev<CR>
" Split navigation
nnoremap <Leader>h <C-w>h
nnoremap <Leader>j <C-w>j
nnoremap <Leader>k <C-w>k
nnoremap <Leader>l <C-w>lPlugins with vim-plug
Install vim-plug:
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vimAdd to .vimrc:
call plug#begin()
Plug 'preservim/nerdtree' " File explorer
Plug 'tpope/vim-fugitive' " Git integration
Plug 'vim-airline/vim-airline' " Status line
Plug 'sheerun/vim-polyglot' " Language support
Plug 'junegunn/fzf.vim' " Fuzzy file finder
Plug 'neoclide/coc.nvim', {'branch': 'release'} " Code completion
call plug#end()Inside Vim, run :PlugInstall to download and install all plugins.
Common Errors
1. Forgetting Which Mode You’re In
Typing dd in Insert mode literally types the letters “dd”. Press Esc to ensure you’re in Normal mode before using commands.
2. Hitting Ctrl+S
Ctrl+S freezes terminal output. Unfreeze with Ctrl+Q. Avoid this key combination in Vim.
3. Not Saving Before Quitting
:q fails with E37: No write since last change. Use :wq to save and quit, or :q! to force quit without saving.
4. Arrow Key Dependency
Arrow keys in Insert mode work, but they break the home-row efficiency that makes Vim fast. Disable them temporarily to force learning:
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>5. Buffer Confusion
Opening many files creates many buffers. Use :ls to list them, :b3 to switch to buffer 3, :bd to close the current buffer.
6. Plugin Not Found
:PlugInstall fails if plug.vim isn’t installed. Run the curl command again. Ensure your .vimrc has call plug#begin() and call plug#end() in the right places.
7. Indentation Wrong for Python
Add this to .vimrc for Python files:
au BufRead,BufNewFile *.py set tabstop=4 shiftwidth=4 expandtabPractice Questions
What are the four modes in Vim? Normal, Insert, Visual, and Command-line.
How do you move down 10 lines in Vim?
10j— the number prefixes the motion.How do you yank (copy) the current line?
yyin Normal mode. Paste withp.What is the substitution command to replace all ‘foo’ with ‘bar’?
:%s/foo/bar/gWhat does
set relativenumberdo? Shows line numbers relative to the cursor position, making5jand12ddeasier.
Challenge: Create a .vimrc from scratch (no copy-pasting). Include: line numbers, tab settings, leader key mappings for save/quit, a file explorer plugin, and a fuzzy finder. Use it for one week without a mouse.
FAQ
What’s Next
| Tutorial | What You’ll Learn |
|---|---|
| Neovim Setup Guide | Modern Vim with Lua configuration and LSP |
| VS Code Guide | GUI editor with Vim emulation extension |
| Linux Administration Basics | Managing servers where Vim is your only editor |
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Updated 2026-06-19.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro