vim-commands.
md 2025-08-21
VIM Modes
Command mode
Default mode
Press Esc to enter command mode.
Edit mode (Insert)
Press i to enter Insert mode.
Edit the file.
Create File Using VIM Editor
vim demo01.c # To create file
ls # Check file in directory
gcc demo01.c -o demo01.out # To compile file
./demo01.out # To run the code
VIM Run Command File (.vimrc)
The .vimrc file is used to configure and customize Vim.
To create:
vim ~/.vimrc
Add the following settings:
set number — Show line numbers
set autoindent — Auto indentation new lines
set tabstop=4 — Tab width = 4 spaces
set smartindent — Smart indentation
set cindent — C language indentation
set shiftwidth=4 — Indent width = 4 spaces
syntax on — Enable syntax highlighting
set nowrap — No line wrapping
set autowriteall — Auto save
set cursorline — Highlight current line
1/3
vim-commands.md 2025-08-21
VIM Commands
Basic
:q — Quit
:w — Write file
:wq — Write and Quit
:q! — Quit without saving
:wqa — Write and Quit All
Copy Commands
yy — Copy current line
4yy — Copy 4 lines from current line
:3,5y — Copy lines 3 to 5
y$ — Copy from cursor to end of line
y^ — Copy from cursor to start of line
yw — Copy current word
2yw — Copy two words from cursor
Cut Commands
dd — Cut current line
3dd — Cut 3 lines from current line
:5,7d — Cut lines 5 to 7
d$ — Cut from cursor to end of line
d^ — Cut from cursor to start of line
dw — Cut current word
2dw — Cut two words from cursor
Paste
p — Paste copied/cut contents
Undo / Redo
u — Undo
Ctrl+R — Redo
Format Document
gg=G — Format/indent entire document
2/3
vim-commands.md 2025-08-21
Multiple File Operation
Example:
vim main.c fun.c
Opens 2 files, shows main.c first.
To go to next file: :next
To go to prev file: :prev
Shortcut : Esc + Ctrl+ww
Save all file changes: :wqa
Open files horizontally:
vim -o file1 file2 file3
Open files vertically:
vim -O file1 file2 file3
3/3