This guide walks you through installing Vim, the powerful terminal-based text editor, on Ubuntu. You’ll learn the exact commands to run, how to verify the installation, and what to do if something goes wrong. No prior experience with the terminal is needed—just follow the steps in order.
What You’ll Need
- An Ubuntu system (desktop or server) with an active internet connection.
- A user account with
sudoprivileges (administrative rights). - Access to a terminal window (Ctrl+Alt+T on desktop, or SSH for remote servers).
Step-by-Step
- Open a terminal. On Ubuntu desktop, press
Ctrl+Alt+T. If you’re on a server, log in via SSH as usual. - Update your package list. Run
sudo apt update. This refreshes the list of available software from Ubuntu’s repositories. Enter your password when prompted (it won’t show as you type). - Install Vim. Run
sudo apt install vim -y. The-yflag automatically confirms the installation prompt. Wait for the download and installation to finish—it usually takes less than a minute. - Verify the installation. Run
vim --version. You should see output starting withVIM - Vi IMprovedand a version number (e.g., 8.2 or 9.0). If you see this, Vim is installed correctly. - Test Vim. Run
vim test.txtto open a new file. You’ll enter Vim’s normal mode. Pressito switch to insert mode, type some text, then pressEscto return to normal mode. Type:wqand press Enter to save and quit. Check that the file was created withls -l test.txt. - Optional: Install Vim’s GUI version (gvim). If you prefer a graphical interface, run
sudo apt install vim-gtk3. This adds thegvimcommand, which opens a windowed editor.
Common Mistakes
- Forgetting to update first. Running
apt installwithoutapt updatemay install an old version or fail if the package index is stale. Always update first. - Typing
vimand getting stuck. New users often don’t know how to exit. PressEscto ensure you’re in normal mode, then type:q!to quit without saving (or:wqto save and quit). - Using
sudounnecessarily. You don’t needsudoto edit your own files. Only usesudo vimwhen editing system files (e.g., in/etc). - Installing the wrong package. Ubuntu offers
vim(minimal),vim-tiny(very limited), andvim-gtk3(with GUI). The standardvimpackage is what most users want.
Tips
- Learn basic Vim commands. Run
vimtutorin the terminal for a 30-minute interactive tutorial that teaches navigation, editing, and saving. - Use a configuration file. Create
~/.vimrcto set options likeset number(line numbers) andset tabstop=4. This makes Vim much more comfortable. - Install plugins. Use a plugin manager like Vundle or vim-plug to add features like file trees, syntax highlighting, and autocomplete. For example, with vim-plug, add
Plug 'preservim/nerdtree'to your.vimrcand run:PlugInstall. - Check for updates. Vim is actively developed. Periodically run
sudo apt update && sudo apt upgrade vimto get the latest version.
Troubleshooting
- “Package ‘vim’ has no installation candidate” — This usually means your package list is outdated or the universe repository is disabled. Run
sudo apt updatefirst. If the problem persists, enable the universe repository withsudo add-apt-repository universethen update again. - Permission denied when installing. If you see
E: Could not open lock file /var/lib/dpkg/lock, another package manager process is running. Wait a few minutes and try again, or reboot if it’s stuck. - Vim opens but looks weird (e.g., arrows print letters). This happens in insert mode. Press
Escto exit insert mode. If arrow keys still don’t work, your terminal may be in a compatibility mode—tryvim -u NONEto see if a plugin is causing issues. - “vim: command not found” after installation. The installation may have failed silently. Run
sudo apt install vimagain and watch for error messages. Also check that your PATH includes/usr/binby runningwhich vim. - Vim is very slow on large files. This is normal for syntax highlighting. Disable it temporarily with
:syntax offor addset lazyredrawto your.vimrc.
Frequently Asked Questions
Is Vim pre-installed on Ubuntu?
Ubuntu includes vi (the older editor) by default, but not full Vim. Run vim --version to check. If it says “command not found”, you need to install it as described above.
What is the difference between vi and vim?
Vim (Vi IMproved) is a superset of vi with additional features like syntax highlighting, undo levels, and visual mode. On Ubuntu, vi is often a minimal version, so installing Vim is recommended for everyday use.
How do I uninstall Vim?
Run sudo apt remove vim. To also remove configuration files, use sudo apt purge vim. This is useful if you want a clean slate.
Can I use Vim to edit system files?
Yes, but you need root privileges. Use sudo vim /etc/hosts (for example). Be careful—mistakes in system files can break your system.
Why does Vim use so much memory?
Vim is lightweight compared to GUI editors, but it can use more memory if you have many plugins or open large files. Disable unused plugins and avoid opening files larger than a few hundred megabytes.
How do I update Vim to the latest version?
Ubuntu’s repositories may lag behind the latest release. To get the newest Vim, you can add the ppa:jonathonf/vim PPA (run sudo add-apt-repository ppa:jonathonf/vim, then sudo apt update && sudo apt upgrade vim). Alternatively, compile from source, but the PPA is simpler.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Show User Library in macOS High Sierra & Sierra
- Device Manager Shortcut: Windows 10 Desktop
- How to Remove Forgotten Passcode from iPhone
- Fix Slow Wi-Fi Problem iPhone X: 9 Steps
- How to Check if a Candidate Accepts Crypto Donations
- How to Listen to Deleted Voicemails on iPhone