Vim is popular and my personal favorite text editor in Linux, providing advance features and functionalities comparative to its competitor, the GNU Nano editor.
Although you can perform basic file editing using both of these programs, Still, they are slightly different from each other, as you can see from the following comparison.
Comparison of Vim and Nano Editor
Vim Editor | Nano Editor |
---|---|
Improved version of Vi editor | Improved version of Pico editor |
Mode-based | Modeless |
Slightly complex for beginners | Peace of cake for beginners |
Supports programming languages | Does not support programming languages |
Advanced editor with many features | Basic editor with limited features |
Tutorial Details
Description | Vim Editor |
Difficulty Level | Moderate |
Root or Sudo Privileges | Maybe |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | vim |
Internet Required | Yes (for installation) |
How to Install Vim on Linux
Although this editor is available in most Linux distributions, if it’s missing from your system, execute any of the following commands, depending on your distribution:
$ sudo apt install vim -y #For Debian/Ubuntu/Pop!_OS
$ sudo dnf install vim -y #For Red Hat/Fedora/CentOS/AlmaLinux
$ sudo pacman -sY vim #For Arch/Manjaro/EndeavourOS
Opening the Vim Editor
Execute the following command with or without specifying the file path.
$ vim
Getting Started
You will get the following window when your launch the Vim editor.
In the Vim editor, you have two types of modes.
- Command-line mode allows you to pass commands into your editor (press “Esc” to enter).
- Insert mode allows you to edit the file (press “i” to enter).
Right now, you are in command-line mode, where you are unable to modify the file. Enter in insert mode by pressing the “i” input key, and you will get the “INSERT
” alert at the bottom.
Now you can start typing your content inside the file; after you’re done, press the Esc key to enter in command-line mode to save the file.
Now press the “:” key to open the command-line interpreter.
To save the file, type the “w“ key with the file name, including the extension, and then press the “enter” key to save the file with that name.
Lastly, your file will be saved in your current location, and you will get the amount of memory used to write it.
To exit from your current active Vim editor hold the “shift” key and press “z” key twice or you can again enter in command-line mode to exit Vim editor by using the “:exit
” command.
If want to open the same file again than specify the path of the file to the vim command as shown.
$ vim file.txt
In case the file does not exists than it will create a new file with specified filename.
Output:
Press the “i” key to enter in insert mode and write your new content again.
This time you can directly hold the shift key and press the “z” key twice to save the file.
From now on, you’ll do most of the things yourself using the different commands shown in the following cheat sheet.
Commands | Actions |
---|---|
h | To move the cursor to the left position |
l | To move the cursor to the right position |
j | To move the cursor to the down position |
k | To move the cursor to the up position |
M | To move the cursor directly to the middle of the screen |
L | To move the cursor directly to the bottom of the screen |
H | To move the cursor directly to the top of the screen |
e | Places the cursor at the end of the word |
b | Places the cursor at the start position of the previous word |
w | Places the cursor at the start position of the next word |
$ | Places the cursor at the end position of the line |
0 | Places the cursor at the start position of the line |
} | Takes the cursor to the start position of the next block or next paragraph |
{ | Takes the cursor to the start position of the previous block or previous paragraph |
) | Moves the cursor directly to the start position of the next sentence |
( | Moves the cursor directly to the start position of the previous sentence |
G | Places the cursor at the end of the file |
gg | Places the cursor at the start of the file |
# | To go on a specific line, type the number of lines next to # |
CTRL + b | Moves the cursor to one page back |
CTRL + f | Moves the cursor to one page forward |
To get the descriptive cheat sheet, please refer to this site.
We will end this conversation here. If you find something missing, do let us know in the comment section.
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.