0% found this document useful (0 votes)
6 views4 pages

Vi Editor: Command and Insert Modes

The document provides information on the vi text editor including its modes (command and insert), basic commands for navigation and editing, and how to exit vi. Command mode is used to give commands to move around and edit the file while insert mode is used to enter text. The escape key returns to command mode from insert mode. Various commands are described for movement, editing, copying/pasting, and more.

Uploaded by

Mankush Jain
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)
6 views4 pages

Vi Editor: Command and Insert Modes

The document provides information on the vi text editor including its modes (command and insert), basic commands for navigation and editing, and how to exit vi. Command mode is used to give commands to move around and edit the file while insert mode is used to enter text. The escape key returns to command mode from insert mode. Various commands are described for movement, editing, copying/pasting, and more.

Uploaded by

Mankush Jain
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

Command Mode

o Command mode is the mode you are in when you start (default mode)
o Command mode is the mode in which commands are given to move
around in the file, to make changes, and to leave the file
o Commands are case sensitive: j not the same as J
o Most commands do not appear on the screen as you type them. Some
commands will appear on the last line: : / ?

Insert (or Text) Mode

o The mode in which text is created. (You must press <Return> at the
end of each line unless you've set wrap margin.)
o There is more than one way to get into insert mode but only one way
to leave: return to command mode by pressing <Esc>

When in doubt about which mode you are in, press <Esc>
From Command Mode

k Up one line

j Down one line

h Left one character

l Right one character (or use <Spacebar>)

w Right one word

b Left one word

From Command Mode

i Enter text entry mode

x Delete a character

dd Delete a line

r Replace a character

R Overwrite text, press <Esc> to end

Displaying Line Numbers


From Command Mode

:set nu Display line numbers

:set nonu Hide line numbers


1. Exiting vi
o To exit you must be in command mode-press <Esc> if you are not in
command mode
o You must press <Return> after commands that begin with a : (colon)
From Command Mode

ZZ Write (if there were changes), then quit

:wq Write, then quit

:q Quit (will only work if file has not been changed)

:q! Quit without saving changes to file

1. More On Cursor Movement


From Command Mode

e Move to end of current word

$ Move to end of current line

^ Move to beginning of current line

+ Move to beginning of next line

- Move to beginning of previous line

G Go to last line of the file

:n Go to line with this number (:10 goes to line 10)

<Ctrl>d Scroll down one-half screen

<Ctrl>u Scroll up one-half screen

<Ctrl>f Scroll forward one full screen

<Ctrl>b Scroll backward one full screen

) Move to the next sentence

( Move to the previous sentence

} Move to the next paragraph

{ Move to the previous paragraph

H Move to the top line of the screen

M Move to the middle line of the screen


L Move to the last line of the screen

% Move to matching bracket: ( { [ ] } )

1. Entering Text Mode


From Command Mode

i Insert text before current character

a Append text after current character

I Begin text insertion at the beginning of a line

A Append text at end of a line

o Open a new line below current line

O Open a new line above current line

1. Deleting Text
From Command Mode

x Delete a character

dw Delete an alphabetic word and the following space


(6dw deletes six words)

dW Delete a blank-delimited word and the following space

dd Delete a line (6dd deletes six lines)

d$ Delete all characters to the end of the line.


D

d} Delete all characters to the end of the paragraph.

:5,30d Delete lines 5 through 30

1. Copying and Pasting Text


From Command Mode

yy Copy (yank) the current line

6yy Copy (yank) six lines, beginning with the current line

yw Copy the current word


p Put the text after the cursor position

P Put the text before the cursor position

1. Other Useful Commands


From Command Mode

. Repeat last command

n. Repeat last command n number of times

J Join next line to current line

u Undo last single change

U Restore current line

Simple process selection : Shows the processes for the current shell –
[root@rhel7 ~]# ps
PID TTY TIME CMD
12330 pts/0 00:00:00 bash
21621 pts/0 00:00:00 ps
Result contains four columns of information.
Where,
PID – the unique process ID
TTY – terminal type that the user is logged into
TIME – amount of CPU in minutes and seconds that the process has been running
CMD – name of the command that launched the process.

[Link]

[Link]

[Link]

Common questions

Powered by AI

In 'vi', to insert text at the beginning of a line, you press 'I' in command mode. This directs the cursor to the start of the current line and switches to insert mode . This command structure suggests that 'vi' was designed to optimize common text operations by assigning intuitive, mnemonic keystrokes that facilitate efficient editorial tasks without needing to remove hands from the standard keyboard position .

To display line numbers in 'vi', you use the command ':set nu' in command mode . This feature is advantageous because it provides a reference for navigation and editing, especially in large files, allowing users to easily track and jump to specific lines, facilitating debugging and precise textual manipulation .

In 'vi', to delete a specific range of lines, you use the command ':start_line_number,end_line_numberd'. For example, ':5,30d' deletes lines 5 through 30 . This feature is significant as it provides precise control over bulk text editing, enabling efficient manipulation of large sections of text without needing to delete lines individually. Such functionality is crucial for tasks involving large sets of data or text within files .

To copy six lines starting from the current line in 'vi', you would use the command '6yy' in command mode . This reflects 'vi's capability to handle text efficiently by allowing users to quickly duplicate multiple lines with minimal keystrokes, facilitating faster editing workflows which is especially valuable in environments requiring frequent manipulation of large text files .

The 'ps' command in Linux is used for monitoring active processes. It typically outputs four columns of information: PID (the unique process ID), TTY (the terminal type that the user is logged into), TIME (the amount of CPU time in minutes and seconds that the process has been running), and CMD (the name of the command that launched the process). This command plays a critical role in system administration by helping users and administrators to understand and manage the processes running on a system .

The '%' command in 'vi' is used to move the cursor to the matching bracket, parenthesis, or brace of the one currently under the cursor . This enhances editing tasks by facilitating the quick identification and navigation between paired symbols, which is particularly useful in programming and markup languages where balanced symbols are common and crucial, thus reducing errors and improving accuracy during code editing and review .

In 'vi', to navigate to the last line of a document, you use the 'G' command in command mode . This method of navigation is efficient because it allows users to quickly jump to any part of the document without scrolling manually, which is particularly useful when dealing with long files. This single keystroke command saves time and improves productivity by minimizing the effort needed for navigation .

To move the cursor to the start of the previous line in 'vi', you can use the '-' key in command mode . This indicates that 'vi's movement controls are designed for efficiency, allowing users to navigate text using simple and intuitive commands that often mirror natural reading and editing directions, such as the use of '-' for previous and '+' for next movements .

In the 'vi editor', command mode is used for navigating within the file, issuing commands to move through text, modifying text, and exiting the editor. Commands in this mode do not appear on the screen as they are typed, except some that show up on the last line, and are case-sensitive . In contrast, insert mode is where text is entered or edited directly. The user can enter insert mode from command mode and leave only by pressing <Esc>, returning to command mode .

In 'vi', you append text at the end of a line by pressing 'A' in command mode . This command switches the editor to insert mode at the end of the current line. The choice of the command key 'A' for 'append' aligns with the initial letter of the action, reinforcing memorability and ease of learning for users who are familiarizing themselves with the command set .

You might also like