Skip to main content

Mastering the VI Editor: A Comprehensive Usage Guide for Linux Enthusiasts

VI Editor: Usage Guide

Aim:

Learn how to use the VI editor for various text editing tasks.

VI Editor: Usage Guide

Guidance on How to Use VI Editor:

i. Edit the File:

To open a file in VI for editing, use the following command:

vi filename.txt
Once in VI:
  • To enter edit mode, press 'i'.
  • To save changes, press 'Esc', then type ':w' and press 'Enter'.
  • To exit VI, press 'Esc', then type ':q' and press 'Enter'.
  • If changes are made and you want to save and exit, type ':wq' and press 'Enter'.

ii. Search Specific Content:

While in command mode (press 'Esc'), use the following command to search for specific content:

:/search_text
To navigate through search results, press 'n' for the next occurrence.

iii. Replace Specific Content:

To replace specific content, use the following command in command mode:

:%s/old_text/new_text/g
This replaces all occurrences of old_text with new_text in the entire file.

iv. Search Content with Special Characters:

To search for content containing special characters, use the following command:

:/@gmail\|\/hms\/logs\|"4
This searches for lines containing @gmail, /hms/logs, or "4.

v. Delete Multiple Lines:

To delete multiple lines, use the following command in command mode:

:1,5d
This deletes lines 1 to 5. Adjust the line numbers as needed.

vi. Select Multiple Lines in Separate File:

To select and copy multiple lines to a separate file, use the following steps:

  • Move the cursor to the starting line.
  • Press 'v' to enter visual mode.
  • Move the cursor to select lines.
  • Press 'y' to copy the selected lines.
  • Open a new file using 'vi newfile.txt'.
  • Press 'p' to paste the copied lines.
  • Save and exit as mentioned in the editing steps.

Verification:

Verify your changes and save the file:

:wq

Written by: A.M.Rinas

Contact: mohomadrinas00@gmail.com

Comments

Popular posts from this blog

MySQL 8.0 Binary Installation: A Step-by-Step Guide

MySQL 8.0 Installation: A Comprehensive Guide Aim : Install MySQL 8.0 using the binary distribution on a Linux system. MySQL 8.0 Installation Steps Step 1: Prepare System and User Create a MySQL group: groupadd mysql Create a MySQL user with restricted shell access: useradd -r -g mysql -s /bin/false mysql Step 2: Download and Extract MySQL Navigate to the installation directory(Not compulsory): cd /usr/local Extract the MySQL tarball: tar xvf /path/to/mysql-VERSION-OS.tar.xz Create a symbolic link: ln -s full-path-to-mysql-VERSION-OS mysql Navigate to the MySQL directory: cd mysql Create a directory for MySQL files: mkdir mysql-files Set ownership and permissio...

Grafana Installation on Ubuntu using Docker

Grafana Installation on Ubuntu using Docker Aim : Install Grafana OSS (open-source version) on Ubuntu using Docker. Grafana Installation Steps Step 1: Pull and Run the Grafana Container Pull and start the Grafana container: sudo docker run -d -p 3000:3000 --name=grafana grafana/grafana-oss -d : Detaches the container and runs it in the background. -p 3000:3000 : Maps port 3000 on your host machine to port 3000 inside the container, enabling access to Grafana's web interface. --name=grafana : Specifies the name of the container as grafana . Step 2: Access Grafana Once the container is running, access Grafana by opening a web browser and navigating to: http://localhost:3000 If Grafana is running on a remote serv...

Apache HTTP Server 2.4.x Installation and Configuration

Apache HTTP Server 2.4.x Installation and Configuration | By A.M.Rinas Aim: Install Apache HTTP Server 2.4.x using the binary distribution and configure it for various purposes. Installation Steps Step 1: Download and Extract Apache HTTP Server Download the Apache HTTP Server 2.4.x binary distribution from the official website. Extract the downloaded tarball: tar xvf httpd-2.4.x.tar.gz Step 2: Configure and Install Apache HTTP Server Navigate to the extracted directory: cd httpd-2.4.x Configure Apache with necessary modules and options: ./configure --enable-proxy --enable-proxy-http --enable-ssl --enable-rewrite Compile and install Apac...