Tech Chronicles

Using the Vi Editor

What is the Vi editor?

Vi is a Notepad-like tool for editing text files from the command line, widely used in the Linux/Unix community. Although it was often thought that Unix had been written by this tool, Vi was originally developed by Bill Joy in 1976. (Unix is based on the year 1969.) According to my personal experience, I can say that 50% of Linux/Unix use is Vi. The beginners have bad experience of editor usage and usually cool open source operating systems off when they are not comfortable to use. (The remaining 50% is the use of shell)

How does Vi work?

Works in 3 different modes;

  1. VI: The editor starts working in this mode, most of the keys on the keyboard are assigned to specific commands. The ESC key is pressed to return from other modes.
  2. Input: You must be in VI mode before you switch to this mode. You can toggle by pressing the “:” (colon), the only exception is to be able to search the status “/” (forward slash).
  3. Command: A mode that allows a user to input data into files.

What are the Vi shortcuts?

If we summarize the shortcuts for three types, we will encounter a table like the following.

  • To display the tables correctly on your mobile device, enable the desktop view in your browser.
Vi Input Command
ESC to exit
$ leftarrow $ $ downarrow $ $ uparrow $ $ rightarrow $ -Cursor keys – insert :q – Quit
H J k L – Cursor keys – append :q! -Output without saving
CTRL-f – Move forward on the screen – Append EOL :w – Write
CTRL-b – Go back on screen O – Open line :Wq – Write and quit
– Go to end of file – Replace character :num – Go to line num
– Delete character R – Overwrite /str – Find str
dw – Delete word :set all – vi settings
dd – Delete line :r file – Import file
yy – Copy line to clipboard
D – Delete to EOL
p – Paste / put buffer
– Undo last command
CTRL-R – Redo last undo
– Find next occurrence of string
cw – Change Word
# command – repeat command # times

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *