0% found this document useful (0 votes)
31 views17 pages

VI Editor

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views17 pages

VI Editor

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

VI editor

Dr. Sarvesh Tanwar


Editors available on Unix
include:
• ed basic line editor
• ex line editor
• vi screen editor
• emacs screen editor

2
VI editor
The VI editor is the most popular and classic text editor in the Linux
family. Below, are some reasons which make it a widely used editor –
• It is available in almost all Linux Distributions
• It works the same across different platforms and Distributions
• It is user-friendly. Hence, millions of Linux users love it and use it for their
editing needs

• An improved version of the vi editor which is called the VIM has also
been made available now. Here, VIM stands for Vi IMproved.
vi is generally considered the de facto standard in Unix editors because
• It's usually available on all the flavors of Unix system.
• Its implementations are very similar across the board.
• It requires very few resources.
• It is more user-friendly than other editors such as the ed or the ex.
• It is available on almost all operating systems.
• A smart range of shortcuts that comprise of short keystrokes.
• You can use vi as an excellent html editor.
• The vi commands are so rich that you hardly need to take your hands off
the keyboard.
• vi editor creates small size files making it light on your storage.
• Its free.
Starting the vi Editor

vi filename
• Creates a new file if it already does not exist, otherwise opens an existing file.

vi -R filename
• Opens an existing file in the read-only mode.

view filename
• Opens an existing file in the read-only mode.
Operation Modes
• Command mode
• Insert mode

Switching between modes


• When you first create or open a file in Vi, you are in Command mode.
Although it seems that you can type here, you can’t. To write
anything, you need to shift to Insert mode by hitting the i key. In order
to shift back to Command mode you simply need to hit the esc key.
• Note: It is important to note that the Vi editor is case-sensitive.
Command Mode
• vi usually launches in Command mode.

• You can perform administrative operations on your files such as saving


a file, execute commands on you file, move cursor across the file, cut
and paste lines and words in a file.

• Command mode also enables you to find and replace text in a file.
Moving cursor across a file:
• You can usually move the cursor across text in your files with the up,
down, left and right arrow keys of your keyboard.
• In case you are using a remote terminal and the arrow keys fail to
behave in the desired manner, you can use the following keys as
substitutes:
• Move left: h
• Move right: l
• Move up: k
• Move down: j

8
Insert Mode
• To enter text in your file, you need to be in the insert mode.
Everything that you type in this mode will be considered text and
added to your file.

• The Esc key will take you to the command mode from insert mode.
To save and quit
• You can save and quit vi editor from command mode. Before writing
save or quit command you have to press colon (:).

• Colon allows you to give instructions to vi.


Inserting or Adding Text

i insert text before cursor, until <Esc> hit


I insert text at beginning of current line, until <Esc> hit
a append text after cursor, until <Esc> hit
A append text to end of current line, until <Esc> hit
open and put text in a new line below current line,
o
until <Esc> hit
open and put text in a new line above current line,
O
until <Esc> hit
exit vi table
Commands Action
:wq Save and quit
:w Save
:q Quit
:w fname Save as fname
ZZ Save and quit
:q! Quit discarding changes made
:w! Save (and write to non-writable file)
:e <filename><enter> Opens the specified file
:r<filename><enter> Reads and inserts the contents of the file after the current line
:w<filename><enter> Writes to specified file
:w! <filename><enter> Forcibly Writes to specified file
:!<command><enter> Executes a shell command

13
To switch from command to
insert mode:
Command Action
i Start typing before the current character

I Start typing at the start of current line

a Start typing after the current character

A Start typing at the end of current line

o Start typing on a new line after the current line

O Start typing on a new line before the current line


To move around a file:

Commands Action

j To move down

k To move up

h To move left

l To move right
To delete
In order to delete a character from your file, move the cursor until it is on the
incorrect letter and then type x key. To remove more characters, say three,
type 3x.
Commands Action

x Delete the current character


X Delete the character before the cursor

r Replace the current character


xp Switch two characters
dd Delete the current line
D Delete the current line from current character to
the end of the line

dG delete from the current line to the end of the file

https://www.javatpoint.com/vi-editor
Copying text

Copying and pasting


yy Use this command to copy the current line
Use this command to paste the copied text
p
after the cursor
Use this command to paste the yanked(cut)
P
text before the cursor

Copies the current word from the character the lowercase


yw w cursor is on, until the end of the word.

You might also like