Here is the complete **HTML version** of the `vi` commands guide with examples:
```html
vi Editor Commands and Examples
๐ vi Editor Commands with Examples
๐น Starting vi
vi filename
This opens filename in vi. If it doesn't exist, vi will create it when saved.
๐ Modes in vi
- Normal Mode: Default mode for navigation and commands.
- Insert Mode: For editing text.
- Command Mode: For file operations (triggered by
:).
✍️ Insert Mode Commands
| Command | Description |
i | Insert before cursor |
I | Insert at beginning of line |
a | Append after cursor |
A | Append at end of line |
o | Open new line below |
O | Open new line above |
Esc | Exit insert mode |
๐งช Example:
Press i → type your text → press Esc to exit insert mode.
๐ File Commands (Command Mode)
| Command | Description |
:w | Save the file |
:q | Quit vi |
:wq | Save and quit |
:q! | Quit without saving |
:w new.txt | Save content to new.txt |
๐ Navigation Commands
| Command | Description |
h | Move left |
l | Move right |
j | Move down |
k | Move up |
0 | Beginning of line |
$ | End of line |
G | End of file |
gg | Start of file |
:n | Go to line number n |
Ctrl+d | Scroll down half page |
Ctrl+u | Scroll up half page |
✂️ Editing Commands
| Command | Description |
x | Delete character under cursor |
dd | Delete current line |
yy | Copy (yank) current line |
p | Paste below |
P | Paste above |
u | Undo last change |
Ctrl+r | Redo |
r<char> | Replace character under cursor |
R | Enter replace mode |
๐ Search and Replace
| Command | Description |
/word | Search forward for "word" |
?word | Search backward for "word" |
n | Repeat last search |
:%s/old/new/g | Replace all "old" with "new" |
:5,10s/foo/bar/g | Replace from line 5 to 10 |
✅ Practical Example
$ vi demo.txt
Then inside vi:
- Press
i and type:
Hello World
This is a test file.
- Press
Esc
- Type
:wq to save and quit
```
You can save this as `vi-commands.html` and open it in any browser.
Would you like a downloadable file version or additional content like visual cheat sheets or keyboard diagrams?
No comments:
Post a Comment