Vim really shines when you customize it. In this final chapter you’ll create a .vimrc, enable helpful defaults, run vimtutor, and gather field-tested tips.
What You Will Do
- Create and configure
.vimrc
- Enable line numbers, syntax highlighting, and other basics
- Use
vimtutor for a condensed practice session
- Learn ten practical tips
Requirements
- A terminal with Vim installed
- Any text editor (Vim itself or something else)
This post assumes a beginner who already finished the earlier Vim chapters and can open Vim from a terminal.
Before You Start
On Linux and macOS, Vim reads ~/.vimrc. On Windows, native Vim usually reads %USERPROFILE%\_vimrc. If you later try Neovim, it uses ~/.config/nvim/init.vim or init.lua instead.
Exercise 1: Create .vimrc
Create the file in your home directory
.vimrc lives in your home directory and stores Vim settings.
Initial screen: Empty file, ~ marks blank lines.
Exercise 2: Enter the default settings
Press i to enter Insert mode
Type the configuration
Enter the following block while in Insert mode:
If you make a typo, do not worry. Save the file first, then use the troubleshooting section to fix the option name and reload the file.
Key settings:
| Setting |
Description |
set number |
Show line numbers |
syntax on |
Enable syntax highlight |
set tabstop=2 |
Tab equals two spaces |
set hlsearch |
Highlight search matches |
set cursorline |
Emphasize the current line |
Exercise 3: Save and exit
Press Esc, then :wq
After you save, Vim returns to the shell. That is the moment when your starter config is written to disk.
Exercise 4: Confirm the settings
Open a new Vim session
When .vimrc loads correctly, Vim reads it automatically at startup and line numbers appear in a new session.
Before the config is loaded in a fresh session: no line numbers.
After settings are applied
Close the empty file with :q, then open Vim again. If you later edit .vimrc while Vim is already open, run :source ~/.vimrc to reload it without restarting.
After reopening Vim: numbers appear on the left margin. The 1 at the left is the line number; the 1,1 at the bottom is still the cursor position.
Quick check from the shell
If you want to confirm the file exists before reopening Vim, this command is safe to copy:
ls -la ~/.vimrc
Exercise 5: Practice with vimtutor
Run vimtutor
vimtutor is Vim’s built-in tutorial.
Estimated time: 25–30 minutes.
Lesson overview:
| Lesson |
Focus |
| Lesson 1 |
Movement, exit, delete |
| Lesson 2 |
Delete, undo, paste |
| Lesson 3 |
Copy, change, substitute |
| Lesson 4 |
Cursor placement, search |
| Lesson 5 |
External commands, save |
| Lesson 6 |
Insert, replace, Visual mode |
| Lesson 7 |
Help system, opening files |
Practical Tips
Tip 1: Temporarily override a setting
These commands change the current session only. When you close Vim, your .vimrc settings take over again the next time you start Vim.
| Command |
Purpose |
:set nu |
Turn line numbers on |
:set nonu |
Turn line numbers off |
Tip 2: Turn them off again when you need a clean view
This is useful when line numbers make copied text harder to read or when you want to compare the screen with another editor.
Tip 3: Substitute across the whole file
:%s/old/new/g replaces every match in the file.
Break it down like this:
: enters command-line mode.
% means "all lines in the current file."
s means substitute.
g means "replace every match on each line."
- Add
c as in :%s/old/new/gc if you want confirmation before each replacement.
If the replacement was not what you wanted, press u to undo it immediately.
| Flag |
Description |
g |
Replace all matches per line |
c |
Confirm each replacement |
More real-world tips
Tip 4: Quick save and exit
:x " Write only if the file changed, then quit
Tip 5: Save without exiting
:w " Write the file and remain in Vim
Tip 6: Move to the end, then append
G " Move to the end of the file
A " Append at the end of the current line
Tip 7: Search
/word " Search for "word"
n " Next match
N " Previous match
Tip 8: Visual mode
v " Character-wise selection
V " Line-wise selection
Ctrl+v " Block selection
Tip 9: Open the help system
:help dd " Help for dd
:help index " Full command index
Tip 10: Command history
: " Enter command-line mode
↑ / ↓ " Browse history
Troubleshooting
Issue 1: E37: No write since last change
Message:
E37: No write since last change (add ! to override)
Cause: Unsaved changes exist.
Fix:
:wq " Save and quit
:q! " Quit without saving
Issue 2: E45: 'readonly' option is set
Message:
E45: 'readonly' option is set (add ! to override)
Fix:
:w !sudo tee % " Write with sudo and prompt for your password
:e " Reload the file inside Vim after the write
Issue 3: Settings not applied
Cause: The file is in the wrong place, Vim is still using an old session, or one of the options contains a typo.
Check:
ls -la ~/.vimrc
- If the file does not exist, go back to Exercise 1 and create it.
- If the file exists, close Vim completely and open it again with
vim test.txt.
- If Vim still ignores the file, run
:echo $HOME inside Vim and make sure it matches the directory where .vimrc lives.
Issue 4: .vimrc syntax error
Message:
Error detected while processing /Users/username/.vimrc:
line 10:
E518: Unknown option: nubmer
Fix:
:e ~/.vimrc " Open the config again
:source % " Reload the current file after fixing the typo
Starter .vimrc Reference
Here is what each starter option does and why it helps a beginner.
| Setting |
Why add it now |
set number |
Shows line numbers for easier navigation and error checking |
syntax on |
Makes code and config files easier to scan |
set tabstop=2 |
Displays a tab as two spaces |
set shiftwidth=2 |
Uses two spaces for auto-indent actions |
set expandtab |
Inserts spaces instead of literal tab characters |
set hlsearch |
Highlights all search matches |
set incsearch |
Updates the search result while you type |
set cursorline |
Helps you keep track of the active line |
set laststatus=2 |
Always shows the status line |
set encoding=utf-8 |
Uses UTF-8 text encoding |
Be careful with these two lines from the sample config:
set nobackup
set noswapfile
They keep your working directory cleaner, but they also remove some crash-recovery help. If you are just starting out, it is fine to delete those two lines until you understand the trade-off.
Optional Next Steps
Path 1: Stay with plain Vim for a week
This is the best next step for most beginners.
- Reuse the commands from this series every day.
- Repeat
vimtutor until movement and save/quit commands feel automatic.
- Add new settings to
.vimrc one at a time so you know what each one changes.
Path 2: Add a plugin manager later
If you want plugins, vim-plug is a common option. This example assumes curl is available on your machine.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
After installing vim-plug, add plugin lines like these inside .vimrc:
" Add inside .vimrc
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-sensible' " Sensible defaults
Plug 'preservim/nerdtree' " File explorer
Plug 'vim-airline/vim-airline' " Better status line
call plug#end()
If you are on Windows or the command fails, check the official installation guide: https://github.com/junegunn/vim-plug
Path 3: Try Neovim later
Neovim is a related editor, but it uses a different config location.
brew install neovim
- Neovim reads
~/.config/nvim/init.vim or init.lua
- It is better to switch after basic Vim commands already feel comfortable
Practice Checklist
Congrats—Vim Series Complete!
You now finished the core Vim series.
What you have learned:
- Why Vim matters
- Installation and first run
- Modes and navigation
- Editing commands
- Configuration and pro tips
Where to go next:
- Use Vim every day
- Repeat
vimtutor a few times
- Gradually add advanced features
Vim Series Overview
| Episode |
Title |
Highlights |
| 1 |
Why Should You Learn Vim? |
Motivation and benefits |
| 2 |
Install and Run Vim for the First Time |
Installation, i, ESC, :wq |
| 3 |
Master Modes and Cursor Movement |
hjkl, w, e, b, gg, G |
| 4 |
Editing Commands |
x, dd, yy, p, u |
| 5 |
Configure Vim—Create .vimrc |
.vimrc, vimtutor |
💬 댓글
이 글에 대한 의견을 남겨주세요