Skip to main content

Working with Vi editor in Unix

Working with Vi editor in Unix

Vi is a very powerful text editor on Unix.

The below resources will help you when dealing with the vi editor in Unix. 

This article is intended to work as a basic starting point or something that you can use on a regular basis for the basic needs. In short, this is a vi survival toolkit.

Basic operation modes

1. Command mode to execute commands on the file with respect to its content.
    Pressing the Esc button will take you to the Command mode.
2. Insert mode to manipulate the text content within the file.
    Pressing the "Insert" key will take you to the insert mode.

Create or Opening a file

vi filename

It will create a file if does not exist, otherwise the file will be opened.

Adding or editing text content

As soon as you open a file in vi, you will be in command mode. To edit the content, press the "Insert" key. This will take you to the Insert mode. Add the content using the keyboard.


Exiting the vi editor

This is by far the task that makes many sweat.

1. When the file content is not changed

Make sure you are in command mode pressing Esc key

:q and press enter key (make a note of the colon)

2. when the file content is changed and you do not want it to be saved[Perhaps the one thing you always should know]

Make sure you are in command mode by pressing Esc key.

:q! and then press enter key

3. when you have changed the file content and it has to be saved

Make sure you are in command mode by pressing Esc key.

:wq and then press enter key


Additional options when dealing with the text content

For the activities like deleting a fill line, some characters, forward and backward string search, please use the below reference.

https://www.cs.colostate.edu/helpdocs/vi.html

Footnote : These are learnings from encounters in the day to day work and there is quite a lot to learn with respect to this tool.

Comments

Popular posts from this blog

Java Keystore - Certificate management

 Java Keystore - Certificate Management Dealing with the Java keystore is not new for the software developers working with Java. But many a times, developers who work with several other technology stack come across the necessity of dealing with java keystoe(jks). A simple, easy way to deal with it is given below. The software The software I am working with is KeyStore Explorer.  This software can be used on Windows, Linux and MacOS. Installable can be downloaded separately. If you are fan of portable apps, you can download the zip version that will work with all the operating systems. This software can be downloaded from the link below  https://keystore-explorer.org/downloads.html Setup Install as per your operating system. For portable version, simply unzip to the desired folder. The Keystore explorer needs a JRE to run. If your laptop has a pre-installed JRE, please make sure the JAVA_HOME environment variable is set. If you already have a portable JRE, you can copy ...

CR-2032 Batteries- Where are they used

 Batteries, CR2032. What is CR2032 (also written CR-2032)? CR2032 is a non rechargeable 3V lithium battery which is used in many electronic devices. It resembles a coin and hence it is also called a coin cell or coin battery.  A Panasonic CR2032 cell What are it's main applications and lifetime in each cases? 1. Car keyfobs . (Lifetime - Normally works for several years, 3-8 years) 2. Apple Airtag. (Lifetime - 1 to 1.5 years) 3. Temperature and humidity sensors. (Around 1-2 years) 4. Toys.(Will run out very soon 😜) 5. Smart home sensors. 6. Calculators. 7. Remote controls for garages etc.

Termux - The android Terminal

Termux No hesitation, you can certainly call Termux “The Android terminal”. Owing to it’s simplicity and capabilities, Termux stand so close to the original Linux terminal. Who is it for and who should read this? This is beginner article which will introduce you to the fundamentals of using Linux terminal on android devices. To understand something here, you should barely understand English and nothing else is a pre-requisite. 🤓 Let us figure out the basics.   Android If you are using an android device, you know that android is the operating system that run the show on your mobile phone. Android is an operating system with its core based on Linux. In fact, android is based on a modified version of Linux optimized for mobile devices. Terminal Terminal is a command line interface which can be used to communicate with or control the Operating system. So, a linux terminal can be used to control a Linux device. Terminal is a tool that comes default with a full fat Unix or Linux opra...