How to Install and Configure Vim on Ubuntu: A Complete Beginner’s Guide

目次

1. Introduction

The Importance of Vim on Ubuntu

On Ubuntu and other Linux distributions, Vim is one of the most important text editors available.
“Vim (Vi IMproved)” is, as its name suggests, an enhanced and extended version of the classic “vi” editor. It offers high-speed operation and flexible customization.
Because Vim is widely used for server administration, programming, and many other tasks in Linux environments, mastering Vim is a significant advantage for Ubuntu users.

Benefits of Using Vim

There are many advantages to installing and using Vim on Ubuntu.
The main benefits are summarized below.

  • Lightweight and fast: Vim launches extremely quickly and runs smoothly even on low-spec systems.
  • Highly customizable: By editing the configuration file (.vimrc), you can build an editor environment tailored to your preferences.
  • Optimized for keyboard use: All operations can be completed using only the keyboard, dramatically improving productivity.
  • Extensible with plugins: You can add features as needed and gradually evolve Vim into your ideal editor.

Purpose and Structure of This Article

The goal of this article is to help you “install Vim on Ubuntu and start using it effectively.”
In addition to installation steps, this guide explains basic configuration, how to set up a Japanese input environment, and how to troubleshoot common issues, all in a beginner-friendly, step-by-step manner.

If you are planning to start using Vim on Ubuntu, this article will guide you through a solid first step. Please read on until the end.

2. Installing Vim on Ubuntu

Checking Whether Vim Is Already Installed

On Ubuntu, a minimal version called “vim-tiny” may be preinstalled by default.
First, open a terminal and run the following command to check whether Vim is installed.

vim --version

If Vim is installed, version information will be displayed.
If you see an error or notice that only a minimal version such as “vim-tiny” is installed, it is recommended to install the full version of Vim.

How to Install Vim

On Ubuntu, Vim can be easily installed using APT (Advanced Package Tool), the standard package management system.
Follow the steps below to install the latest version of Vim.

1. Update the package list

First, update the system’s package list to the latest state.

sudo apt update

2. Install Vim

Next, install Vim.

sudo apt install vim

The required packages will be downloaded and installed automatically.
When prompted with “Do you want to continue? [Y/n]”, press Y and hit Enter.

Checking the Vim Version

After installation is complete, check the Vim version again.

vim --version

The output includes the installed version number and build options such as +clipboard.
If +clipboard is enabled, you can copy and paste between Vim and the system clipboard, which significantly improves usability.

Optional: Installing Vim via the GUI Software Center (For Beginners)

If you are not comfortable using the terminal, you can also install Vim via Ubuntu Software (the Software Center).

  1. Launch “Ubuntu Software” from the application list
  2. Enter “Vim” in the search bar
  3. Select Vim from the results and click the “Install” button

This method allows you to install Vim intuitively without using command-line operations, making it ideal for Linux beginners.

3. Basic Vim Configuration

The Role of the .vimrc File and How to Create It

The configuration file used to customize Vim’s behavior is called .vimrc.
By writing settings in this file, they are automatically applied at startup, allowing you to create a more comfortable editing environment.

Typically, the .vimrc file is placed in the user’s home directory (~/.vimrc).
If the file does not exist, create it using the following command.

touch ~/.vimrc

After creating it, open the file with Vim or any editor to edit it.

vim ~/.vimrc

Recommended Basic Settings for Beginners

Below are some essential settings recommended for those who are new to Vim on Ubuntu.

Display line numbers

Line numbers are very useful when editing code or text.

set number

Enable syntax highlighting

This makes code easier to read by applying colors based on syntax.

syntax on

Adjust indentation settings

This configuration standardizes indentation to four spaces, improving readability.

set tabstop=4
set shiftwidth=4
set expandtab

Ignore case when searching

This setting allows searches to match text regardless of letter case.

set ignorecase
set smartcase

ignorecase always ignores case, while smartcase becomes case-sensitive only when uppercase letters are included in the search term.

Saving and Applying Settings

After editing the .vimrc file, save it and restart Vim.
Vim loads .vimrc at startup, so closing and reopening the editor applies the settings.

You can also reload the configuration instantly by running the following command inside Vim.

:source ~/.vimrc

This is useful when testing configuration changes without restarting Vim.

4. Setting Up a Japanese Input Environment

Installing and Configuring a Japanese Input Method (IME)

To input Japanese text in Vim, a Japanese input method (IME) must be properly installed on Ubuntu.
Common options include “fcitx-mozc” and “ibus-mozc”. Below are two widely used methods.

Installing fcitx-mozc

Fcitx is a lightweight and fast IME framework widely used by Ubuntu users.
You can install Fcitx and the Mozc Japanese input engine with the following commands.

sudo apt update
sudo apt install fcitx-mozc

After installation, change the keyboard input system to “fcitx” in the system’s language support settings.
Log out and log back in to activate Fcitx.

Installing ibus-mozc

If you prefer Ubuntu’s default input system, IBus, install Mozc using the following commands.

sudo apt update
sudo apt install ibus-mozc

After installation, go to “Region & Language” in system settings, add “Japanese (Mozc)” as an input source, and the setup will be complete.

Important Notes When Using Japanese Input in Vim

Because Vim was originally developed for English-based environments, there are some important considerations when using Japanese input.

Differences in IME behavior by mode

Vim has a “Normal mode” and an “Insert mode.”
Japanese input is generally needed only in Insert mode.
If the IME is active in Normal mode, it may cause unintended command execution. Being mindful of switching IME states by mode can improve workflow efficiency.

Compatibility issues between Vim and IME

In some Ubuntu environments, IME may not work properly within Vim.
In particular, terminal-based Vim may fail to display the candidate window correctly, depending on the environment.

In such cases, using the GUI version of Vim (e.g., gvim) or adjusting settings such as fonts and encoding may resolve the issue.

Configuring IME Shortcut Keys

Setting shortcut keys for switching between Japanese and English input improves efficiency.

For example, when using Fcitx, follow these steps.

  1. Open the Fcitx configuration screen
  2. Select the “Global Config” tab
  3. Set the input method toggle key to your preferred key (e.g., the Half-width/Full-width key)

This allows quick switching between Japanese and English input across all applications, including Vim.

5. Creating a More Comfortable Vim Environment

Recommended Plugins

Vim is powerful even with its default features, but plugins can further enhance comfort and efficiency.
Below are some especially recommended plugins for Vim on Ubuntu.

vim-airline

vim-airline enhances Vim’s status line with a clean and informative design.
It displays information such as file name, line number, and encoding at a glance, improving productivity.

Installation example:

Plug 'vim-airline/vim-airline'

nerdtree

nerdtree displays a file tree inside Vim.
It allows you to visually navigate directory structures like a GUI editor, which is especially useful for large projects.

Installation example:

Plug 'preservim/nerdtree'

To launch NERDTree, use the following command.

:NERDTreeToggle

Installing a Plugin Manager (vim-plug)

Using a plugin manager makes it easier to manage multiple plugins.
Here, we introduce “vim-plug”, a simple and popular choice.

How to Install vim-plug

  1. Download and place vim-plug.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs   https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  1. Add the plugin list to .vimrc.
call plug#begin('~/.vim/plugged')

Plug 'vim-airline/vim-airline'
Plug 'preservim/nerdtree'

call plug#end()
  1. Launch Vim and run the following command.
:PlugInstall

The configured plugins will be installed automatically.

Improving Cursor Movement During Japanese Input

When typing Japanese, cursor movement may feel sluggish or unstable.
There are several ways to improve this behavior.

Automatic IME on/off by Vim mode

Automatically toggling IME based on Vim mode helps prevent accidental input and enables smoother Japanese typing.
This can be achieved using plugins such as “fcitx.vim”.

Using skkeleton (for Neovim)

For Neovim users, the Japanese input plugin “skkeleton” has gained attention.
It allows native Japanese input control inside Vim, providing a very smooth editing experience.

6. Troubleshooting

If Vim Does Not Start or Displays Errors

After installing Vim, you may encounter startup errors or find that Vim does not start at all.
Common causes include the following.

  • Dependency packages were not installed correctly
  • Errors in the .vimrc configuration file
  • Permission issues preventing required files from being read

How to Resolve

  1. First, confirm that Vim is installed correctly.
vim --version
  1. If installation issues are suspected, uninstall and reinstall Vim.
sudo apt remove vim
sudo apt install vim
  1. If .vimrc is causing issues, you can start Vim while ignoring the configuration file.
vim -u NONE

If Vim starts normally, review the contents of your .vimrc.

If Japanese Input Does Not Work

On Ubuntu, Japanese input issues may occur not only in Vim but system-wide.
Because Vim depends on proper IME integration, check the following points.

  • Is your IME (fcitx or ibus) running correctly?
  • Is Japanese input enabled in system settings?
  • Are font and encoding settings correctly configured in the terminal?

If terminal-based Vim does not work well, using the GUI version (gvim) may help.

Checklist When Settings Are Not Applied

If changes in .vimrc are not reflected, check the following items.

  1. Is the .vimrc file in the correct location?
  • Expected path: ~/.vimrc
  1. Is the file name correct?
  • Ensure correct capitalization (use .vimrc, not .Vimrc).
  1. Are there any syntax errors?
  • Even a single typo can invalidate a Vim command.
  1. Did you restart Vim after saving the file?
  • Alternatively, apply changes immediately using the following command.
:source ~/.vimrc

Following this checklist resolves most configuration issues.

7. Conclusion

Steps to Start Using Vim on Ubuntu

In this article, we covered the entire process of using Vim on Ubuntu—from installation and basic configuration to Japanese input setup, plugin usage, and troubleshooting.

In summary, you can start using Vim by following these steps.

  1. Install Vim via the terminal or Ubuntu Software
  2. Create a .vimrc file and apply basic settings such as line numbers and syntax highlighting
  3. Install fcitx-mozc or ibus-mozc to enable Japanese input
  4. Enhance productivity with plugins like vim-airline and nerdtree
  5. Troubleshoot startup or Japanese input issues as they arise

By following these steps, even beginners can comfortably use Vim on Ubuntu.

Next Steps: Taking Vim Further

This guide covers only the first step of using Vim.
Thanks to its deep customization and powerful features, Vim becomes more rewarding the more you learn.

As next steps, consider exploring the following topics.

  • Automation using Vim scripts (VimL)
  • Advanced programming support with LSP (Language Server Protocol)
  • Migrating to Neovim and leveraging its extended ecosystem
  • Optimizing writing workflows with seamless Japanese and English switching

Enjoy the process of building your own ideal editor environment.