Installing Vim (text-editor) on an EC2 instance running Ubuntu is a straightforward process. Regardless of whether you’re using Ubuntu 20.04 LTS (Focal Fossa) or the newer 22.04 LTS (Jammy Jellyfish) or even on your local WSL Ubuntu, the steps remain the same. This short guide will walk you through the installation procedure.
Prerequisites
Before starting, you should have:
- An AWS EC2 instance running Ubuntu 20.04 or 22.04, refer to my official guide on how to deploy EC2 Ubuntu on AWS.
- SSH access to your instance.
Ensure that your instance is up-to-date with:
sudo apt update && sudo apt upgrade -y
Step 1: Connect to Your EC2 Instance
SSH into your EC2 instance using its IP address or DNS name:
ssh -i /path/to/your-key.pem ubuntu@your_ec2_ip_address
Replace /path/to/your-key.pem
with the path to your private key file, and your_ec2_ip_address
with your actual EC2 IP address or DNS name.
Step 2: Install Vim
Once logged in, install Vim by running:
sudo apt update sudo apt install vim -y
This command downloads and installs the Vim editor on your Ubuntu system.
Step 3: Verify the Installation
Check that Vim has been installed correctly:
vim --version
The output should display the version of Vim that’s been installed, along with its configuration details.
Additional Tips
If you need advanced features, consider installing vim-gtk3
 for a fully-featured graphical version, or vim-nox
 for a feature-rich console version:
sudo apt install vim-gtk3 -y # For the GUI version with extra features
or
sudo apt install vim-nox -y # For the console version with extra features
Basic Guide to Using Vim for Beginners
These are some basic commands to get you started with Vim:
- Opening Vim: To open a file in Vim, simply type
vim
followed by the name of the file you want to edit. For example, to edit a file named “example.txt”, you would typevim example.txt
and press Enter. - Switching between modes: Vim has different modes for editing text. The two main modes are “Normal” mode and “Insert” mode. To switch from Normal mode to Insert mode, press the
i
key. To switch back to Normal mode from Insert mode, press theEsc
key. - Editing text: In Insert mode, you can type and edit text as you would in any other text editor. To navigate within the file, use the arrow keys or the
h
,j
,k
, andl
keys (left, down, up, right respectively) in Normal mode. - Saving changes: To save your changes and exit Vim, first switch to Normal mode if you’re not already in it by pressing
Esc
, then type:w
and press Enter. This command saves the changes but does not exit Vim. - Exiting Vim: To exit Vim without saving changes, type
:q!
and press Enter. If you’ve made changes and want to save them before exiting, type:wq
and press Enter. If you’re not sure if you’ve made changes and want to exit, type:q
and press Enter.
As you become more familiar with the editor, you can explore additional features and commands to further improve your productivity.
Conclusion
You now have Vim installed on your EC2 Ubuntu instance. Enjoy the efficiency and power of one of the most popular text editors in the Unix-like world. Whether you are writing code, configuring files, or simply taking notes, Vim is a reliable and versatile tool that can enhance your productivity.