Do you know all about vi Editor?

Do you know all about vi Editor?

Vi or the Visual Editor is the default text editor that comes with most Linux systems. It is a Terminal-based text editor that users need to learn, essentially when more user-friendly text editors are not available on the system.

Nowadays, there are advanced versions of the vi editor available, and the most popular one is VIM which is VImproved.

How to use 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


Modes of Operation in vi editor

  1. COMMAND MODE
No alt text provided for this image

The vi editor opens in this mode, and it only understands commands In this mode, you can, move the cursor and cut, copy, paste the text . This mode also saves the changes you have made to the file . Commands are case sensitive . This mode is where vi interprets any characters we type as commands and thus does not display them in the window

2. INSERT MODE

No alt text provided for this image

This mode is for inserting text in the file. To enter text, you must be in insert mode. To come in insert mode you simply type i.  Once you are in Insert mode, any key would be taken as an input for the file on which you are currently working. To get out of insert mode, press the Esc key, which will put you back into command mode.

Saving and Closing the file

Shift+zz - Save the file and quit

:w - Save the file but keep it open

:q - Quit without saving

:wq - Save the file and quit

Copying (Yanking)

To copy text, place the cursor in the desired location and press the y key followed by the movement command. Below are some helpful yanking commands:

yy - Yank (copy) the current line, including the newline character.

3yy - Yank (copy) three lines, starting from the line where the cursor is positioned.

y$ - Yank (copy) everything from the cursor to the end of the line.

y^ - Yank (copy) everything from the cursor to the start of the line.

yw - Yank (copy) to the start of the next word.

yiw – Yank (copy) the current word.

y% - Yank (copy) to the matching character. By default supported pairs are (), {}, and []. Useful to copy text between matching brackets.

Cutting (Deleting)

In normal mode, d is the key for cutting (deleting) text. Move the cursor to the desired position and press the d key, followed by the movement command. Here are some helpful deleting commands:

dd - Delete (cut) the current line, including the newline character.

3dd - Delete (cut) three lines, starting from the line where the cursor is positioned,

d$ - Delete (cut) everything from the cursor to the end of the line.

The movement commands that apply for yanking are also valid for deleting. For example dw, deletes to the start of the next word, and d^ deletes everything from the cursor to the start of the line.

Pasting (Putting)

To put the yanked or deleted text, move the cursor to the desired location and press p to put (paste) the text after the cursor or P to put (paste) before the cursor.

Moving within a file

k - Move cursor up

j - Move cursor down

h - Move cursor left

l - Move cursor right


Other useful commands

a - Write after cursor (goes into insert mode)

A - Write at the end of line (goes into insert mode)

ESC - Terminate insert mode

u - Undo last change

U - Undo all changes to the entire line

o - Open a new line (goes into insert mode)

cw - Change word

x - Delete character at the cursor

r - Replace character

R - Overwrite characters from cursor onward

s - Substitute one character under cursor continue to insert

S - Substitute entire line and begin to insert at the beginning of the line

~ - Change case of individual character

$ - Positions cursor at end of line.

W - Positions cursor to the next word.

B - Positions cursor to previous word.

( - Positions cursor to beginning of current sentence.

) - Positions cursor to beginning of next sentence.

H - Move to top of screen.

nH - Moves to nth line from the top of the screen.

M - Move to middle of screen.

L - Move to bottom of screen.

nL - Moves to nth line from the bottom of the screen.

colon along with x - Colon followed by a number would position the cursor on line number represented by x.

w! fileName - Overwrite to file called file Name (save as forcefully).

!cmd - Runs shell commands and returns to Command mode.


No alt text provided for this image

Tejas Gupta

[email protected]
































Geetansh Sharma

Systems Engineer at Tata Consultancy Services | 3x AWS certified | 3x RedHat Certified | AWS Certified Developer Associate | RedHat Certified Engineer | RedHat Certified System Administrator

3 年

It's quite useful

回复

Very much helpful

回复
Niharika D.

AWS Community Builder | DevOps Aspirant | ARTH Learner Openshift | Ansible | Kubernetes | Docker | Jenkins | Full Stack Web Developer

3 年

Thank you for sharing, turned out be actually very useful.

回复
Nayan Jodhawat

Actively Looking for Change | DevOps Engineer | CKA | AWS SAA-C02 | RHCSA | RHCE | Azure | Docker | Kubernetes | Terraform | Ansible

3 年

Very much useful ??

回复

要查看或添加评论,请登录

Tejas Gupta的更多文章

  • Ace AWS Cloud Practitioner Certification

    Ace AWS Cloud Practitioner Certification

    Hello Everyone , I recently cleared AWS cloud Practitioner exam and would like to share some learning strategies and…

    6 条评论
  • <script>...</script>

    <script>...</script>

    JavaScript is a dynamic programming language that's used for web development, in web applications, for game…

    1 条评论
  • Confusion Matrix - IDS

    Confusion Matrix - IDS

    A confusion matrix is a summarized table of the number of correct and incorrect predictions (or actual and predicted…

    3 条评论
  • Cisco using MongoDB

    Cisco using MongoDB

    What is MongoDB? MongoDB is a document-oriented NoSQL database used for high volume data storage. Instead of using…

  • CISCO WITH OPENSHIFT

    CISCO WITH OPENSHIFT

    Red Hat OpenShift is a multifaceted, open source container application platform from Red Hat Inc. for the development…

  • Industry use cases on Jenkins

    Industry use cases on Jenkins

    What is Jenkins? Jenkins is an open source Continuous Integration server capable of orchestrating a chain of actions…

  • CASE STUDY OF AWS SQS

    CASE STUDY OF AWS SQS

    What is Amazon SQS? Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to…

  • SIEMENS Healthineers With Azure Kubernetes Service (

    SIEMENS Healthineers With Azure Kubernetes Service (

    Lets start with a statistics This itself explain why do we need to have knowledge of Azure Kubernetes Service What is…

  • Facebook with a surprise

    Facebook with a surprise

    The basic idea behind a neural network is to simulate (copy in a simplified but reasonably faithful way) lots of…

  • Ansible session with experts of Redhat

    Ansible session with experts of Redhat

    ??Hello Connection?? Yesterday on 28th December 2020 I attended an "Ansible Industry Experts Practical Demo " arranged…

社区洞察

其他会员也浏览了