In this guide, we will learn how to install Vim on CentOS. This text editor is one of the oldest and one of the best text editors for Linux.
It is a greatly improved version of a good old Vi Editor, packed with many great features like command line history, syntax highlighting, multi-level undo, spelling checker, block operations, and filename, etc.
When it comes to efficient and versatile text editing, Vim stands as a cornerstone in the world of programming and development. Whether you’re a seasoned coder or a novice explorer, having the Vim text editor at your fingertips can greatly enhance your productivity and streamline your editing workflows.
Throughout this guide, we’ll walk you through the simple and straightforward process of installing Vim on CentOS, ensuring that you’re equipped with this powerful tool to tackle a wide range of text manipulation tasks.
After following this guide, you’ll have Vim up and running on your CentOS, ready to revolutionize the way you approach coding, scripting, and text editing.
Let’s dive into the installation process and unlock the potential of Vim’s capabilities on your CentOS environment.
Key Features of Vim Text Editor
Vim, a highly versatile and widely used text editor, boasts a rich set of features that make it a favorite among programmers, developers, and text manipulation enthusiasts.
Some of its key features include:
- It is a cross-platform editor which is available for Linux, Windows, and Mac operating systems.
- It can be accessed from both the command line interface (CLI) and Graphical User Interface (GUI).
- It is a high-level text editor suitable for editing Markup Languages.
- Modal Editing: One of Vim’s defining characteristics is its modal editing approach. It offers different modes (normal, insert, visual, command-line, etc.), allowing users to seamlessly switch between them for various tasks, enhancing efficiency.
- Extensibility: Vim supports a wide range of plugins and extensions, enabling users to customize and enhance its functionality to suit their specific needs. This extensibility makes it a powerful tool for diverse programming and editing tasks.
- Efficient Navigation: Vim provides numerous keyboard shortcuts and commands that streamline navigation within files. Features like search, replace, and jump-to-line make it easy to move around large codebases quickly.
- Text Manipulation: With a wide array of text manipulation commands, Vim enables users to edit, delete, copy, paste, and rearrange text with remarkable precision. Regular expressions and global substitutions further enhance its text-editing capabilities.
- Split Windows: Vim allows users to split the editing window horizontally and vertically, enabling side-by-side comparisons, simultaneous editing of multiple files, and efficient code debugging.
- Syntax Highlighting: Vim supports syntax highlighting for a vast number of programming languages and file formats. This feature improves code readability by colorizing different code elements.
- Auto-Completion: Vim offers intelligent auto-completion features that suggest words, phrases, and even code snippets as you type, helping to reduce typing errors and speed up the coding process.
- Registers: Vim’s registers allow users to store and recall text snippets, enabling copy-paste operations between different parts of the document or even across files.
- Undo/Redo: Vim maintains an extensive undo history, enabling users to backtrack through their editing changes and redo them if necessary. This feature helps prevent accidental data loss.
- Remote Editing: Vim can be used for remote editing via SSH, allowing users to edit files on remote servers directly from their local Vim instance.
- Command-Line Integration: Vim seamlessly integrates with the command line, enabling users to perform various tasks without leaving the editor, such as running shell commands, compiling code, and managing files.
- Macros: Vim’s macro functionality allows users to record and playback a series of commands, automating repetitive tasks and saving time.
These features, among others, contribute to Vim’s enduring popularity as a powerful and efficient text editor.
Its steep learning curve is well worth the investment for those seeking an editing tool that offers exceptional flexibility and productivity.
How to Install Vim on CentOS
You need to run the command below to install Vim on CentOS:
sudo yum install vim
Once you hit enter, it will prompt you with [y/d/N]. You need to press y to continue the installation. It will install Vim and all the dependencies (vim-enhanced & vim-common).
A Beginner’s Guide to Vim
Opening Vim
You can use vim
commands with sudo
privilege to open an existing file. For example:
sudo vim name_of_the_document
Let’s take another example and create another document with the file name “index.html” and add some HTML
code in the file. To do that, run:
sudo vim newdocument.html
Now, let’s add some html
codes in it:
Main Heading Goes Here
Sub-Heading Goes Here
Paragraph Goes Here
Link
Another Sub-Heading Goes Here
Paragraph Goes Here
Link
To save changes press the colon :
and then wq!
to save and quit the changes.
Modal Editing
Most text editors have only one mode while Vim editor also has another mode called “Modal Editing” mode. This is the key difference between Vim and any other text editor.
In “Modal Editing”, some special functions get enabled to help you perform copying text by holding multiple modifier keys and then hitting a regular key.
Vim text editor uses these distinct modes to separate these functions from the normal input task.
Let’s check these modes one by one:
Normal Mode
It is used for editing operations like copy-pasting, deleting, moving, and editing text.
By default, Vim starts in “normal” mode. If you are in some other mode, you can return to the normal mode by pressing the escape button ESC or
.
In normal mode, key presses do not work. But there are certain actions that you can perform to move the cursor.
Move the cursor
h
– move one character leftj
– move one row downk
– move one row upl
– move one character right
As with many Vim commands, row movement can be prefixed by a number to move s several lines at a time:
To move several lines, rows, and characters, you can prefix a number.
4j
– This will move 4 rows down10l
– This will move 10 characters right
Basic word movements:
w
– move to the beginning of the next wordb
– move to the beginning of the previous worde
– move to the end of the wordW
– move to the beginning of the next word after a white spaceB
– move to the beginning of the previous word before a white spaceE
– move to the end of the word before a white space
moving to the Beginning & End of the line:
0
– move to the beginning of the line$
– move to the end of the linegg
– move to the top of the document.G
– move to the bottom of the document. You can also prefix a number to go to that line number.w
– move to the next word. Prefix a number to move that many words.b
– move back one word. Prefix a number to move back to that many words.e
– move to the end of the word. Prefix a number to move that many words.
Insert Mode
Insert mode is used for inserting new text in the document. It enables multiple editing options:
i
– Enters into the insert mode at the current cursor position.a
– Enters into the insert mode after the current position.o
– Inserts a new line below the current line. Also enters insert mode on the new line.I
– Enters into the insert mode at the beginning of the current line.A
– Enters insert mode at the end of the current line.O
– inserts a new line above the current line. Also enters insert mode on the new line.
To leave insert mode, press Esc
or
Visual Mode
This third mode used by Vin Editor is known as the Visual Mode which is used for visual selection such as copying, pasting, deleting, replacing, and so on.
v
– To enter regular visual mode. This will mark a selection point and selections can be made by moving the cursor right, left, up, and down.V
– To enter visual line mode. It makes text selection by line. This means that entire lines can be selected, from the first to the last character, by moving the cursor.-
[ctrl]-v
– To enter visual block mode. It selects the whole block. Moving the cursor up or down can select multiple lines of text.
Press ESC
or
, to leave the visual mode and return to normal mode.
Command Mode
Command Mode is used for running Vim commands. To enter into Command Mode, you simply need to hit the colon key.
:
– Enters command mode.
Command mode has a variety of powerful features which can make your task a lot easier. For example, to do a global search and replace, you just need to type:
:%s/foo/bar/g
This particular command will replace all “foo” with “bar”.
:
Enters command mode%
Across all liness
Substitute/foo
is the regex to find things to replace/bar/
is the regex to replace things with/g
means global. If not mentioned, it would only execute once per line
For Vim-related help or documentation, you can also run:
:h
or
:help
Editing
For editing purposes, Vim Editor must be in Normal mode to issue commands.
Here are some of the actions that you can perform:
Deleting text
x
– to delete the character under the cursor.d
– to delete text that {motion} moves over. For example, the “dl” command will delete a character to the right.dd
– to delete a line.D
– to delete from the current position to the end of the line.
Changing Text
r
– It replaces the character under the cursor with some other character you input. You just need to substitute the character after issuing this command.c
– It changes the text in the direction that follows. For example, if you press “cw”, the Vim editor will take you to the Insert Mode where you can input your replacement text.C
– It changes the text to the end of the line.
Copying and Pasting
y
– to copy in the direction that follows.yy
– to copy the entire line.Y
– to copy until the end of the line.p
– to paste the last line copied or deleted below the current line.P
– to paste the last line copied or deleted above the current line.
Miscellaneous Editing
u
– Undo
– Redo-r J
– Join the current and below lines.
Documents Management
To manage the document you must be inside the command line mode of the Vim editor. As you already know to enter in command line mode. You need to press colon “:” to enter and perform these commands below:
:q
– to quit Vim.:q!
– to forcefully quit Vim and discard any unsaved changes.:w
– to save changes. You can also add a space and then a filename if you would like to save the file to a different location.:e
– to dit the file that follows.:bn
– to edit the next file that Vim has open.:bp
– to edit the previous file that Vim has open.
For more Vim Command and shortcuts, you can visit Vim Documentation.
You may also like:
Conclusion
In conclusion, you’ve now completed the straightforward process of installing Vim on CentOS by following the easy steps outlined in this guide. Vim, a powerful and versatile text editor, is now at your disposal, enabling you to enhance your coding and text manipulation tasks with efficiency and precision.
By effortlessly navigating through the installation steps, you’ve unlocked the potential of Vim’s features and capabilities on your CentOS system. This essential tool can significantly boost your productivity and streamline your editing workflows.
I hope this guide on how to install Vim on CentOS has proven to be helpful and informative. With Vim at your fingertips, you’re equipped to tackle a wide range of editing tasks with confidence.
Should you have any questions or insights to share, feel free to leave your comments below.
Thank you for choosing this guide, and may your Vim experience be both productive and rewarding.