Discovery of Vi and Vim Editors: Users Best Friends in Linux

Discovery of Vi and Vim Editors: Users Best Friends in Linux

Photo by Sigmund on Unsplash

Introduction

Imagine you have a magic wand that lets you edit text in a super cool and powerful way. Well, that's kind of what Vi and Vim editors are! They are special tools that help you modify text files, like documents or code, using commands in a fancy computer command-line environment.

These editors have been around for a really long time and have become legendary among tech-savvy folks. They may look a little tricky at first, but once you get the hang of them, they can make your text editing tasks super easy and efficient.

So, let's embark on an exciting journey to discover the magic of Vi and Vim editors and how they can transform the way you work with text on your computer!

Vi Editor

Vi, short for "visual," was introduced in the early 1970s, making it one of the oldest text editors still in active use. Its minimalistic interface might appear daunting at first, but once you grasp the basics, you'll find it incredibly efficient.

Imagine you want to edit a file called "example.txt." Simply open your terminal and type:

[root@192 Desktop]# vi example.txt

Voila! You're now in Vi's command mode. To start editing, press the 'i' key for insert mode, and you can begin typing your content. Pressing the 'Esc' key takes you back to command mode, where you can execute various commands or navigate through your text.

Vim Editor

Vim, short for "Vi Improved," which took the foundation of Vi and expanded upon it with a wealth of additional features and extensive customization capabilities. Vim retains all the commands and modes of Vi while incorporating powerful enhancements.

To open a file using Vim, enter the following command:

[root@192 Desktop]# vim example.txt

You can easily personalize your Vim experience by customizing your .vimrc file, where you can define key mappings, color schemes, and much more.

How to Vi/ Vim?

Editors work on three modes:

  1. Insert Mode

  2. Command Mode

  3. Execution Mode


Vi and Vim may seem intimidating at first, but mastering them can turn you into a command-line wizard. Here are a few essential commands to get you started:

  1. Delete Operation:

    1. dd - To delete entire line

    2. 5dd - To delete entire 5 lines at one

    3. D - To delete a line after the cursor

    4. 5D - To delete 5 lines after the cursor

  2. Saving and Quitting:

    • To save changes and exit Vim, use the command :wq.

    • To quit without saving, type :q!.

  3. Searching:

    • Press the '/' key followed by your search query to find text within the file.

    • Use 'n' to jump to the next occurrence.

  4. Copy, Cut, and Paste:

    • yy- To Copy content from a line

    • 5yy- To Copy next five lines from the position on cursot

    • p- To Paste the content you copied earlier

  5. Screen Navigation:

    • H - Head of the screen

    • M - Middle of the screen

    • L - Bottom of the Screen

  6. Display Lines: :

    1. set su - To Display the line number in the editor

    2. set nonu - To remove the line number

  7. Search and Replace operations:

    1. %s/<old-word> /<new-word> - To replace a single old word with new word

    2. %s/<old-word> /<new-word>/g - To replace new word on all Places

  8. Read one file in another

    1. :r <filename> - To read on file in another file

Conclusion

Vi and Vim may seem like relics from the past, but they remain essential tools for many Linux enthusiasts. Their speed, efficiency, and extensibility have earned them a dedicated fan base. So, if you're willing to invest some time in mastering these editors, you'll be rewarded with unparalleled control over your text editing workflow. Embrace the command line and let Vi and Vim empower you to new heights!

So, go ahead and dive into the world of Vi and Vim. Your fingers will soon be dancing across the keyboard, effortlessly manipulating text with the grace of a seasoned pro!