2.8 KiB
Getting Started with Vim 📝
1. Installing Vim
To install Vim on a Debian‑based system (like Ubuntu), run:
sudo apt update
sudo apt install vim
2. Opening Files or Directories
-
Open a file
vim <filename> -
Open a directory
vim <directory_name>(This opens Vim’s file browser—helpful for navigating and editing multiple files.)
3. Vim Modes
Vim works in multiple modes—here are the core ones:
- Normal mode – The default mode; used for navigation and commands.
- Insert mode – For editing text; enter it by pressing
i,a, oro. - Visual mode – For selecting text; enter it with
v,V, orCtrl+v.
4. Essential Commands
(Type these in Normal mode and then press Enter when needed)
| Command | Description |
|---|---|
:w |
Save (write changes to the current file) |
:w <name> |
Save changes to a specified file <name> |
:wq |
Save and quit Vim |
:q |
Quit (only if no unsaved changes exist) |
:q! |
Quit without saving (discard all changes) |
5. Handy Shortcuts
These are core shortcuts used in Normal mode:
| Shortcut | Action |
|---|---|
dd |
Delete (cut) the current line |
yy |
Yank (copy) the current line |
p |
Paste after the cursor |
u |
Undo the last change |
gg |
Go to the first line of the file |
6. Quick Usage Flow
-
Start Vim:
vim example.txt -
Insert text: Press
i→ type your content → pressEscto return to Normal mode. -
Save your work: Type
:win Normal mode and press Enter. -
Make edits:
- Use
ddto delete a line - Use
yyto copy (yank) a line - Move the cursor to a new location, then hit
pto paste - Press
uto undo any mistake
- Use
-
Navigate quickly:
ggto jump to the beginning- Use arrow keys or
h,j,k,lfor navigation
-
Finish editing:
:wqto save and exit:q!to exit without saving
7. Tips & Tricks
-
Visual mode: Press
vto start selecting character by character,Vfor line selection, orCtrl+vfor block-wise selection. -
Other navigation:
- Use
Gto go to the end of the file - Use a number before a command, e.g.,
5dddeletes 5 lines
- Use
Summary
Vim may feel different at first, but once you get comfortable switching between Insert, Normal, and Visual modes, you'll find it’s a powerful and efficient editor. Happy Vimming! 😊