Vi Editor Basics Quiz
22 Questions
2 Views

Vi Editor Basics Quiz

Created by
@CalmSerpentine8789

Questions and Answers

What is the default mode when entering the vi editor?

  • COMMAND mode (correct)
  • TEXT mode
  • EDIT mode
  • INSERT mode
  • Which command is NOT used to enter INSERT mode?

  • d (correct)
  • i
  • o
  • a
  • How do you exit INSERT mode in vi?

  • Press the ESC key (correct)
  • Press Enter
  • Type :wq
  • Type dd
  • Which command is used to write a file in vi?

    <p>:w filename</p> Signup and view all the answers

    In vi, which command allows you to search for text?

    <p>/.../</p> Signup and view all the answers

    What command is used to replace a string globally in the Vi editor?

    <p>:%s/.../.../g</p> Signup and view all the answers

    Which command would you use to copy text into a buffer in the Vi editor?

    <p>y'a</p> Signup and view all the answers

    How do you write the current file in Vi?

    <p>:w</p> Signup and view all the answers

    What command would you use to delete text into a buffer?

    <p>d'a</p> Signup and view all the answers

    Which command allows you to move to the third line in a file using Vi?

    <p>:3</p> Signup and view all the answers

    What command deletes text from the current cursor position to the beginning of the line?

    <p>d^</p> Signup and view all the answers

    Which command is used to delete from the current cursor position to the end of the word?

    <p>Dw</p> Signup and view all the answers

    How can you view all possible settings in the current session?

    <p>:set all</p> Signup and view all the answers

    What is the purpose of the command ':set nu'?

    <p>To set line numbers</p> Signup and view all the answers

    Which setting indicates that the editor will not automatically save files when quitting?

    <p>noautowrite</p> Signup and view all the answers

    What command is used to write the file and quit the editor in Vi?

    <p>:wq</p> Signup and view all the answers

    What does the command 'dd' accomplish in Vi?

    <p>Delete the current line</p> Signup and view all the answers

    In Vi, which command allows you to search backward for a pattern?

    <p>?...?</p> Signup and view all the answers

    What is the purpose of the command 'u' in Vi?

    <p>Undo the last command</p> Signup and view all the answers

    Which command is used to permanently save changes made during a Vi session?

    <p>:w</p> Signup and view all the answers

    What does the command '^f' do in the context of Vi?

    <p>Displays the next segment of the file</p> Signup and view all the answers

    How can one recover a file in Vi that was not saved properly?

    <p>vi -r filename</p> 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, or o, and exited with ESC.

    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 with G.
    • 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, use u or U.
    • Recovery from unexpected closure can be done using vi -r filename.

    Insert/Delete Functions

    • Delete current line with dd, current character with x.
    • Insert text before or after the current character using i or a, and after the current line with o.

    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 with d'a, and paste with p.
    • For copying, use y'a instead of d'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, or G for the last line.

    Additional Commands

    • Yank a character with yl, or a word with yw.
    • Delete from current position to the beginning of the line using d^, or to the end with d$.
    • 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.

    Quiz Team

    Related Documents

    3- VI editor.pdf

    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.

    More Quizzes Like This

    CS131 Week 3
    19 questions

    CS131 Week 3

    RefinedBowenite avatar
    RefinedBowenite
    Mastering File Handling in Big Data
    6 questions
    Vim Editor History and Features
    10 questions
    Unix VI Editor Commands
    10 questions

    Unix VI Editor Commands

    FastPacedDada5626 avatar
    FastPacedDada5626
    Use Quizgecko on...
    Browser
    Browser