Using vi Editor

Vi is the one of the mostly used editor in Linux via terminal. In most cases where Linux is used as a server operating system, admins use the terminal, where GUI uses more system resources & network bandwidth. Since Vi is used from the terminal, the lack of GUI force the user to learn function keys of the editor. Vi is a powerful and functional application if it is used with the ideas that is built on.

To run vi, type vi from the terminal, vi is installed on most of the Linux distros as default. You may also you the improved version called “Vim” if you are developing codes or scripts. If you don’t have vim installed just run the command to install “yum install vim-enhanced -y“.

To create a new file just write the name of the file after the command as follows:

vi /root/newfile.txt

For more functionality Vi is designed to work in three modes described below:

  1. Command Mode
  2. Edit (editing + adding) Mode
  3. Command Line Mode

Vi starts in Command mode, thus you cannot directly start typing or editing the lines inside the editor. You can always return to command mode by pressing ESC button anytime. To switch to Editing mode while you are in command mode press “ESC” and type “:” or press “Insert” button on your keyboard.

Below are the mostly used functions in Command Mode::

Command Action
i Switches to Insert (edit) Mode
a Switches edit mode at the end of cursor
A Switches edit mode at the end of current line
ESC Closes edit mode and switches to Command Mode
u Undo
U Undo all
o Insert new line
dd Delete whole line
/string makes search for the “string”
n Search next item

To switch to Command Line mode press ESC and type “:” without quotes. Below are the commands that you can use in command line mode:

Command Action
ZZ Saves the current file and exits or
wq w for saving, q to exit
w! saves read-only files (force)
q! Quit without saving
q Quit
  • 7 Користувачі, які знайшли це корисним
Ця відповідь Вам допомогла?

Схожі статті

Setting time with NTP in LINUX

NTP (Network Time Protocol) could be used to set time synced with ntp clocks, to do this use the...

Linux version & Operating System info

LINUX Version Info To learn the architecture and kernel version info use the shell command...

Compile and build Apache + MySQL + PHP from the source [cite]

This is a complete working solution to build Apache (httpd-2.2.25), MySQL (MySQL-5.6.14) and PHP...

Build PHP5.5 on CentOS 6.4 with MSSQL Support [cite]

Most of the yum repos doesn’t include PHP5.5.X on current releases for the time being. So...

Installing MS SQL Module to PHP on DirectAdmin [cite]

If you need to connect to an MS Sql Server remotely from your DirectAdmin server via php, you...