Questions and Answers
What is the default mode when entering the vi editor?
Which command is NOT used to enter INSERT mode?
How do you exit INSERT mode in vi?
Which command is used to write a file in vi?
Signup and view all the answers
In vi, which command allows you to search for text?
Signup and view all the answers
What command is used to replace a string globally in the Vi editor?
Signup and view all the answers
Which command would you use to copy text into a buffer in the Vi editor?
Signup and view all the answers
How do you write the current file in Vi?
Signup and view all the answers
What command would you use to delete text into a buffer?
Signup and view all the answers
Which command allows you to move to the third line in a file using Vi?
Signup and view all the answers
What command deletes text from the current cursor position to the beginning of the line?
Signup and view all the answers
Which command is used to delete from the current cursor position to the end of the word?
Signup and view all the answers
How can you view all possible settings in the current session?
Signup and view all the answers
What is the purpose of the command ':set nu'?
Signup and view all the answers
Which setting indicates that the editor will not automatically save files when quitting?
Signup and view all the answers
What command is used to write the file and quit the editor in Vi?
Signup and view all the answers
What does the command 'dd' accomplish in Vi?
Signup and view all the answers
In Vi, which command allows you to search backward for a pattern?
Signup and view all the answers
What is the purpose of the command 'u' in Vi?
Signup and view all the answers
Which command is used to permanently save changes made during a Vi session?
Signup and view all the answers
What does the command '^f' do in the context of Vi?
Signup and view all the answers
How can one recover a file in Vi that was not saved properly?
Signup and view all the answers
Study Notes
Overview of VI Editor
- VI is available on most UNIX systems and compatible with various terminals.
- Customizable editing environment without the need for special keyboard definitions.
Performance Objectives
- Start and exit VI using commands like
vi
,ESC
,:wq
. - Cursor movement commands include:
h
(left),j
(down),k
(up),l
(right),^f
(forward),^b
(backward). - Text manipulation commands:
i
(insert),a
(append),x
(delete character),dd
(delete line). - Searching and replacing text:
/pattern/
,:n
,:s/pattern/replacement/g
. - Text movement and copying:
ma
(mark),d'a
(delete to mark),p
(paste). - File operations:
:w filename
(write file),:r filename
(read file). - Vi environment tailoring using
:set options
.
Vi Modes
- COMMAND mode: Default mode for executing commands. Enter using
:
. - INSERT mode: Used for entering text, activated by
i
,a
, oro
, and exited withESC
.
Window Positioning
- Move window forward or backward:
^f
for 32 lines,^b
for 32 lines back. - Move to specific line with
:n
or to end of file withG
. - Cursor movement can also be performed using
h
,j
,k
,l
.
Making Changes Permanent
- VI uses a temporary file for changes. Use
:w
to write changes to the file. - Exit and save changes with
:wq
. To undo changes, useu
orU
. - Recovery from unexpected closure can be done using
vi -r filename
.
Insert/Delete Functions
- Delete current line with
dd
, current character withx
. - Insert text before or after the current character using
i
ora
, and after the current line witho
.
Additional VI Functions
- Open multiple files using
vi file1 file2...
and exit without saving using:q
. - Redraw the screen using
^l
. - Join lines with
J
.
Searching and Replacing
- Search forward with
/pattern/
and backward with?pattern
. - Advance to next occurrence with
n
. - Replace pattern on the same line with
:s/pattern/replacement/
or globally with:%s/pattern/replacement/g
.
Moving and Copying Text
- Mark the start position with
ma
, delete text to a buffer withd'a
, and paste withp
. - For copying, use
y'a
instead ofd'a
.
Writing to a File
- Write the current file with
:w
and overwrite another file using:w!
. - Write specific lines to a named file with
m,nw filename
.
Useful Commands
- Re-edit the current file and discard changes with
:e
. - Edit a specific file with
:e filename
. - Insert contents of another file at the cursor with
:r filename
. - Execute shell command and return to VI using
:!cmd
.
Go to Specific Line
- Navigate to a specific line using
:linenumber
, e.g.,:3
for the third line,:1
for the first line, orG
for the last line.
Additional Commands
- Yank a character with
yl
, or a word withyw
. - Delete from current position to the beginning of the line using
d^
, or to the end withd$
. - Delete to the end of the current word with
dW
.
Tailoring the VI Environment
- Set options for the current session with
:set option
. - Example:
:set nu
to display line numbers. - View all possible settings with
:set all
, including options for indentation, file handling, and display configurations.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge on the essential commands and modes of the vi editor. This quiz covers default modes, text insertion, file writing, and string replacement in vi. Perfect for beginners looking to strengthen their understanding of this powerful text editor.