Software Engineer's Blog

Stop Fighting Your IME in Vim - Auto-Switch with vim-im-select

Stop Fighting Your IME in Vim - Auto-Switch with `vim-im-select`

The Problem

If you use a multilingual Input Method Editor (IME) like ibus for Korean, Japanese, or Chinese, you know this pain: you’re in Insert mode typing in your native language, you press Esc to go to Normal mode, and you try to run a command like j or dd. Instead of moving the cursor, you get “ㅓ” or “ㅇㅇ” typed on the screen.

You have to manually switch your IME back to English every time you enter Normal mode. This breaks your flow and is incredibly frustrating.

The Solution: vim-im-select

vim-im-select is a lightweight Vim plugin that solves this problem completely. It automatically switches your system’s IME based on Vim’s mode:

  • Esc (Insert -> Normal): Automatically switches your IME to English.
  • i (Normal -> Insert): Automatically restores whatever IME you were using before (e.g., Korean).

It’s a “set it and forget it” solution that makes Vim seamless for multilingual users.

Installation and Configuration Guide (Ubuntu with vim-plug + ibus)

Here is the quick setup guide.

1. Install the Plugin with vim-plug

Add the plugin to your ~/.vimrc file inside the plug#begin() section. We’ll use the popular brglng fork:

call plug#begin('~/.vim/plugged')

" ... other plugins ...
Plug 'brglng/vim-im-select'

call plug#end()

Save the file, restart Vim, and run :PlugInstall to install it.

2. Configure for ibus

The plugin is installed, but it doesn’t know how to control your specific IME yet. You must tell it which commands to use.

Add the following configuration to the bottom of your ~/.vimrc:

" --- vim-im-select Configuration (for ibus) ---

" 1. Set the default English keyboard for Normal Mode
let g:im_select_default = 'xkb:us::eng'

" 2. Command to get the *current* IME status
let g:im_select_get_im_cmd = "ibus engine | awk '{print $1}'"

" 3. Command to *set* a specific IME
let g:im_select_set_im_cmd = "ibus engine %s"
  • **im_select_default**: This is your base English keyboard. (xkb:us::eng is the standard on most Ubuntu systems).
  • get_im_cmd: This command checks what your current active IME is (e.g., “hangul”).
  • **set_im_cmd**: This is the command the plugin uses to switch your IME, with %s being replaced by the IME name (e.g., ibus engine xkb:us::eng).