Unicode, in particular UTF-8 encoding, is now the de facto standard for writing on the web. In this article, I describe how I set up Vim to make it easy to write using Unicode characters that aren’t on my keyboard (e.g., ☹︎, ☺, and ♥). In a nutshell, I set up Vim to use:
Whether you use terminal Vim or GUI Vim, put the following in your
If you use terminal Vim, you also need to configure your terminal emulator to use UTF-8 encoding. The way to do that depends on your terminal emulator.
Choosing a font is a huge topic, but for this article I’ll just say that you want a font that:
The monospace fonts that I use are DejaVu Sans Mono, Monaco, and Consolas. DejaVu Sans Mono is free/gratis and free/libre. Monaco is included on Macs and Consolas is included on Windows. Neither Monaco nor Consolas are free/libre.
The way to tell Vim which font to use depends on whether you are using a GUI Vim, such as gVim or MacVim, or terminal Vim. If you use terminal Vim, specify the font in your terminal emulator’s configuration.
If you use a GUI Vim, put something like the following in your
if has("gui_running") set guifont=DejaVu_Sans_Mono:h16 endif
DejaVu_Sans_Mono:h161 with the font and size you want to use. I
recommend putting this in an if-block so you can use this
vimrc for both terminal Vims
and GUI Vims. If you use the same
vimrc across multiple devices, you can specify a list
of guifonts like this:
if has("gui_running") set guifont=DejaVu_Sans_Mono:h16,Monaco:h16,Consolas:h12 endif
Vim will use the first font that’s available on the current device.
Vim has built-in digraphs, which are standard 2-character keyboard shortcuts for entering Unicode characters that are specified in RFC 1345: Character Mnemonics and Character Sets. To learn about Vim’s digraphs, type the following in Vim in command-mode.
:help digraph.txt :help digraph-table :help digraph-table-mbyte :help dig :dig
You can also read the above built-in Vim Help files on the web at Vim documentation: digraph.
Here’s an excerpt from
char digraph hex dec official name ☺ 0u 263A 9786 WHITE SMILING FACE ♡ cH 2661 9825 WHITE HEART SUIT
To insert a character using its digraph, do the following:
For example, to enter a White Smiling Face (☺), type the following in insert-mode:
To enter a White Heart Suit (♡), type the following in insert-mode:
The default digraphs are hard to remember and almost every time I use one I need to look it up by typing:
:help digraph-table /string
string is part of the name of the character that I’m searching for. For example, to find
the above characters (☺ and ♡), I search the digraph-table using
To make my life easier, I’ve set my own personal easy-to-remember digraphs in my
are some of my
vimrc dig settings:
dig :( 9785 dig :) 9786
To learn more about these commands, see either:
:help ga :help :as
These two commands are equivalent and are sometimes called the “get ascii” command. You can read the Vim Help file either within Vim or at Vim documentation: various #ga.
Tip: If you find a Unicode character that you’d like to create a Vim digraph for, copy & paste it into your
vimrc, use the “get ascii” (
ga) command to find its decimal representation, and then create your digraph with the appropriate
vimrc, replace the space with either underscore (
_) or backslash-space (