Information Technology Tips

Innotechtips_logo_v4
Menu
  • Home
  • Linux
  • Programming
  • Other Tech Tips
    • Windows
    • Security
Youtube
Home Linux

Vi/Vim Text Editor-Basic Operations

Inno by Inno
July 27, 2023
Vi/Vim Text Editor-Basic Operations

Vi/Vim Text Editor-Basic Operations

Vi is one of the available tools for editing text in Linux and Unix-like systems. Vi is the original text editing tool that runs in the terminal. Vim is an improved version of vi that adds features such as text highlighting.

Vi Modes

Before one can begin using vi, it is important to understand the two modes associated with vi. The first mode is the command mode or normal mode. This is the default mode of vi. However, while in command mode we can search and manipulate text but we cannot input text. The screenshot below shows a file opened using vi and is currently in command mode. In the bottom left we can see the name of the file, ‘testfile’.

The second mode is the input mode where we are able to edit text. To get to the input mode from the command mode, there are various keys that we can press. For instance, one can press ‘i’ (for insert)or ‘o’ (for new line)or ‘a’. Once we are done editing a file, we will need to get back to command mode in order to save the file. To get back to the command mode from the input mode, we are able to achieve this by pressing the ESC key. The screenshot below shows the input mode. In the bottom left we have the word ‘INSERT’.

Once we are in command mode, we will be able to save our changes by typing:

:wq >> means write and quit as shown below.

:wq! >> means write and quit and do not complain (or force the write action).

:q! >>quit without saving the changes as shown below.

Other commands we can use while in command mode:

gg >> takes you to the top/beginning of the file.

/’text_to_search_for’  >> Can be used to search for text or a word. In the below example, we are searching for the word ‘great’ using the syntax, /great.

To select a block of text, we can press v for visual and then use arrow keys to select a block of lines. The below screenshot shows the word visual in the bottom left that is displayed after we have pressed the v key.

Use y to yank or copy text. The below screenshot displays the message ‘6 lines yanked’ at the bottom left of the screen after we press the key y to copy the 6 highlighted lines of text.

To delete text, we can use d for delete.

When we want to paste text we can use p.

To delete a line of text, we can place the cursor at the beginning of a line and use dd.

To undo changes, we can leverage the key, u.

To replace text use:

:%s/good/great/g

In this example, s stands for substitute, ‘good’ is the word to be replaced by the word ‘great’, and g stands for global or occurrences on the entire file.

To learn more about vi, type the command, vimtutor in the terminal. This will walk you through the different vi options and commands.

Inno

Inno

Related Posts

Linux

Getting Started with Kali Linux: A Guide for Beginners

July 31, 2024
Linux

20 Linux Commands for Beginners

March 31, 2024
Linux

What is KVM Virtualization?

March 31, 2024
Linux

The Linux Booting Process in Linux

February 17, 2024

Category

  • Linux
  • Other Tech Tips
  • Programming
  • Windows

Recommended.

File Permissions in Linux

June 17, 2024

IPv4 to IPv6 Transition Challenges

July 27, 2023

Trending.

How to Install and Enable Free VPN in Kali Linux

July 27, 2023

How To Connect Kali Linux to Wi-Fi on VirtualBox

October 9, 2023

How to Connect Kali Linux on VMware Workstation to a Wi-Fi Network

July 27, 2023
How to Connect to Kali Linux from Window’s Command Prompt

How to Connect to Kali Linux from Window’s Command Prompt

July 27, 2023

How to Capture Network Traffic on a Wi-Fi Network using Kali Linux

July 27, 2023

About us

This site is dedicated towards highlighting various important aspects of information technology. The key areas includes programming, Linux, software, and security. The content will include articles as well as videos.

Quick Links

Menu
  • Home
  • Linux
  • Programming
  • Other Tech Tips
    • Windows
    • Security

Privacy Policy

Menu
  • Privacy Policy
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}
No Result
View All Result
  • Cookie Policy (EU)
  • Home 1
  • Home 2
  • Home 3
  • Mytest Page
  • Privacy Policy

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.