0% found this document useful (0 votes)
11 views

Vi Editor Command Mode

Unix

Uploaded by

Amit Katkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Vi Editor Command Mode

Unix

Uploaded by

Amit Katkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

The vi editor (short for Visual Editor) is a text editor in Unix/Linux

systems used to create, edit, and view files. It’s a powerful tool for
editing configuration files, scripts, and general text. It operates in
two primary modes: command mode and insert mode.and total
eske pass 4 modes hote hai command mode,insert mode,execute
mode,read only mode

Command Mode in vi Editor

command mode is the default mode when you open a file. This
mode is used to navigate the file, delete or move text, search for
words, and execute various commands.

Real-time Use of Command Mode :

In real-time, command mode is widely used for editing system


configurations,scripts, and working with logs

Key Commands in Command Mode

1. Navigation Commands:

Here are the top 5 most commonly used navigation commands in


the vi editor:

1. h, j, k, l:
○ h: Move left (one character).
○ j: Move down (one line).
○ k: Move up (one line).
○ l: Move right (one character).
2. w and b:
○ w: Move to the beginning of the next word.
○ b: Move to the beginning of the previous word.
3. 0 and $:
○ 0: (this is zero)Move to the beginning of the current line.
○ $: (this is dollar)Move to the end of the current line.
4. G and gg:
○ G: (capital G) Go to the last line of the file.
○ gg: Go to the first line of the file.
5. Ctrl + f and Ctrl + b:
○ Ctrl + f: Scroll forward one screen.
○ Ctrl + b: Scroll backward one screen.

2. Editing and Deleting Commands:

● dd: Delete the entire current line.


● d$: Delete from the cursor to the end of the line.
● x: Delete the character at the cursor.
● u: Undo the last action.
● yy: Copy the current line (yank).
● p: Paste the yanked
● dw: Delete from the cursor to the beginning of the next word.
● cw: Change (replace) the current word (switches to insert
mode).
● r: Replace the character under the cursor.
● :set number
● line_number+Capital G =10G

3. Search and Replace Commands:

● /pattern: Search for a pattern in the file.


○ Example: /error searches for the word "error".
● n: Jump to the next occurrence of the searched pattern.
● N: Jump to the previous occurrence of the searched pattern.
● :%s/old/new: Replace all occurrences of old with new in the
entire file.
● :s/old/new: Replace the first occurrence of old with new on
the current line.

4. File Operations:
● :w: Save (write) the file.
● :q: Quit the editor.
● :wq: Save and quit.
● :q!: Quit without saving (force quit).
● :w [filename]: Save the file with a different name.
● :e [filename]: Open a new file within the same vi session.

5. Advanced Commands:

● J:(capital J) Join the current line with the next line.


● o: Open a new line below the current line and switch to insert
mode.
● O: Open a new line above the current line and switch to insert
mode.

You might also like