Which of the following commands can be used to open it in the writing mode?

The lowly and now middle-aged vi editor is still a favorite among *nix system administrators and remains an essential tool for command-line file creation and editing.

Posted: August 20, 2019 |%t min read| by Ken Hess (Sudoer alumni, Red Hat)

Image

Which of the following commands can be used to open it in the writing mode?

"VI vs. Emacs" by mrbill is licensed under CC BY 2.0 

Gray at the temples and in need of reading glasses, the middle-aged Vi (pronounced vee-eye) editor, released in 1976, is still a system administrator's best friend.

This advanced, yet straightforward command-line editing program shows no sign of slowing down. You can use it to edit configuration files, create a grocery list, write a letter home to ask for money, create a new script, or even edit source code. 

Vi is often a symbolic link to Vim (Vi Improved) or an alias to Vim, an enhanced version of Vi.

[ Get the Vim cheat sheet. ]

It’s easy to invoke Vi. At the command line, you type vi to create a new file, or to edit an existing one.

$ vi filename.txt

Career advice

  • Take a sysadmin skills assessment
  • Explore training and certification options
  • Red Hat Certification remote exams FAQ
  • Get essential IT career advice from IT leaders

Vi edit modes

The Vi editor has two modes: Command and Insert. When you first open a file with Vi, you are in Command mode. Command mode means you can use keyboard keys to navigate, delete, copy, paste, and do a number of other tasks—except entering text.

To enter Insert mode, press i. In Insert mode, you can enter text, use the Enter key to go to a new line, use the arrow keys to navigate text, and use vi as a free-form text editor. To return to Command mode, press the Esc key once.

[ Get more out of your text editor: 5 Vim features for power users. ]

In Vi's Command mode, almost every letter on the keyboard has a function.

To save a file, you must first be in Command mode. Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit. In Vi, write means save, and quit means exit. If you’ve made mistakes along the way while editing and want to back out (abandon) all non-saved changes, enter Command mode by pressing Esc and typing :q! This command quits without saving any changes and exits Vi.

Note: Always make a copy of an existing file prior to editing with Vi or any editor. This is especially critical when editing system and configuration files.

Image

Which of the following commands can be used to open it in the writing mode?

Download now

Vi shortcuts

The best way to learn Vi is to create a new file and try it out for yourself. Feel free to use the common keyboard shortcut list below to help you learn Vi’s extensive vocabulary. This list of shortcuts is by no means exhaustive, but they will enable you to edit files and learn Vi in a short amount of time.

  • $ vi — Open or edit a file.
  • i — Switch to Insert mode.
  • Esc — Switch to Command mode.
  • :w — Save and continue editing.
  • :wq or ZZ — Save and quit/exit vi.
  • :q! — Quit vi and do not save changes.
  • vi 2 — Yank (copy) a line of text.
  • vi 3 — Paste a line of yanked text below the current line.
  • vi 4 — Open a new line under the current line.
  • vi 5 — Open a new line above the current line.
  • vi 6 — Append to the end of the line.
  • vi 7 — Append after the cursor’s current position.
  • vi 8 — Insert text at the beginning of the current line.
  • vi 9 — Go to the beginning of the word.
  • i0 — Go to the end of the word.
  • i1 — Delete a single character.
  • i2 — Delete an entire line.
  • i3 — Delete X number of lines.
  • i4 — Yank X number of lines.
  • i5 — Go to the last line in a file.
  • i6 — Go to line X in a file.
  • i7 — Go to the first line in a file.
  • i8 — Display the current line’s line number.
  • i9 — Move left one character.
  • :wq0 — Move down one line.
  • :wq1 — Move up one line.
  • :wq2 — Move right one character.

[ Want to switch your text editor? Download the Emacs cheat sheet. ]

Image

Which of the following commands can be used to open it in the writing mode?

Linux skills: 9 tutorials to get more from your text editor

Are you getting everything you need out of your text editor? Read Enable Sysadmin's recent articles about Linux text editors to find out what you're missing.

Posted: July 22, 2022

Author: Vicki Walker (Editorial Team, Red Hat)

Image

Which of the following commands can be used to open it in the writing mode?

How to get started with the Vi editor

Once you've committed Vi's keyboard shortcuts to muscle memory, watch how fast you work.

Posted: January 25, 2022

Author: Seth Kenlon (Editorial Team, Red Hat)

Image

Which of the following commands can be used to open it in the writing mode?

Top five Vim plugins for sysadmins

My list of the top five Vim plugins—plus a bonus.

Posted: October 16, 2020

Author: Ricardo Gerardi (Sudoer, Red Hat)

Topics:   Command line utilities   Text editors   Linux  

Which of the following commands can be used to open it in the writing mode?

Ken Hess

Ken has used Red Hat Linux since 1996 and has written ebooks, whitepapers, actual books, thousands of exam review questions, and hundreds of articles on open source and other topics. Ken also has 20+ years of experience as an enterprise sysadmin with Unix, Linux, Windows, and Virtualization. More about me

Red Hat Summit 2022: On Demand

Get the latest on Ansible, Red Hat Enterprise Linux, OpenShift, and more from our virtual event on demand.

Register for free

Image

Which of the following commands can be used to open it in the writing mode?

How to schedule jobs using the Linux 'cron' utility

Scheduling tasks to run automatically at specific times is essential knowledge for any sysadmin.

Posted: December 15, 2022

Author: Alexon Oliveira (Sudoer, Red Hat)

Image

Which of the following commands can be used to open it in the writing mode?

Learn how Unix influenced Linux, understand Ansible lists and dictionaries, and more tips for sysadmin

Which of the following command is used to open a file for writing only?

Write Only ('w'): This mode opens the file for writing only. The data in existing files are modified and overwritten.

Which symbol is used for opening a file in writing mode?

w+ : Opens a file for writing and reading.

Which of the following is used to open text file for writing in appending mode?

a. Open a text file in append mode for writing at the end of the file. The fopen() function creates the file if it does not exist and is not a logical file.

Which of the following is correct to open a text file for write mode in Python?

You can do this with the write() method if you open the file with the "w" mode. As you can see, opening a file with the "w" mode and then writing to it replaces the existing content. 💡 Tip: The write() method returns the number of characters written.