Thursday, May 1, 2025

vi commands

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

CommandDescription
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
oOpen new line below
OOpen new line above
EscExit insert mode

๐Ÿงช Example:

Press i → type your text → press Esc to exit insert mode.

๐Ÿ“‚ File Commands (Command Mode)

CommandDescription
:wSave the file
:qQuit vi
:wqSave and quit
:q!Quit without saving
:w new.txtSave content to new.txt

๐Ÿ” Navigation Commands

CommandDescription
hMove left
lMove right
jMove down
kMove up
0Beginning of line
$End of line
GEnd of file
ggStart of file
:nGo to line number n
Ctrl+dScroll down half page
Ctrl+uScroll up half page

✂️ Editing Commands

CommandDescription
xDelete character under cursor
ddDelete current line
yyCopy (yank) current line
pPaste below
PPaste above
uUndo last change
Ctrl+rRedo
r<char>Replace character under cursor
REnter replace mode

๐Ÿ” Search and Replace

CommandDescription
/wordSearch forward for "word"
?wordSearch backward for "word"
nRepeat last search
:%s/old/new/gReplace all "old" with "new"
:5,10s/foo/bar/gReplace from line 5 to 10

✅ Practical Example

$ vi demo.txt

Then inside vi:

  1. Press i and type:
  2. Hello World
    This is a test file.
  3. Press Esc
  4. 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

Sudo Command Details

sudo -l -U a762311 Output : User a762311 may run the following commands on MACLB390804