0 Dummies Guide to the status bar symbols (Powerline fonts) on Fedora, Ubuntu and Windows
Ian Channing edited this page 2018-08-07 11:44:36 +02:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This took hours to figure out, so here's more of a dummies guide for Fedora/Ubuntu, with a special section for Windows.

The first is figuring out what the hell are those strange but nice angle brackets that appear in the vim-airline status bar. The background is that airline is a pure vim version of powerline (which was python), and powerline uses UTF-8 characters to insert those angle brackets. So vim-airline just uses the same UTF-8 characters.

Then even if you do manage to get one installed they look uglier than you'd hope because the fonts don't fully work.

So what we're doing is installing some custom fonts that have specific UTF-8 characters and then specifying those characters in the status bar.

Configuring Vim

This is opposite to the official instructions but my .vimrc configuration following those instructions didn't work at the end which made me question all the font installations. So I suggest you get this configured first and then if you get the fonts working it should magically appear.

The final trick was forcing vim-airline to use the fonts it needs. In the official documentation it should just be adding let g:airline_powerline_fonts = 1 in your .vimrc. However I did this and no luck. There's more information in :help airline-customization and that gives you some simple config settings that you need, just in case. This was the final magic sauce that I needed. I don't know why this wasn't automatically created. This is also mentioned in this Vi Stack Exchange answer.

    if !exists('g:airline_symbols')
        let g:airline_symbols = {}
    endif

    " unicode symbols
    let g:airline_left_sep = '»'
    let g:airline_left_sep = '▶'
    let g:airline_right_sep = '«'
    let g:airline_right_sep = '◀'
    let g:airline_symbols.crypt = '🔒'
    let g:airline_symbols.linenr = '☰'
    let g:airline_symbols.linenr = '␊'
    let g:airline_symbols.linenr = '␤'
    let g:airline_symbols.linenr = '¶'
    let g:airline_symbols.maxlinenr = ''
    let g:airline_symbols.maxlinenr = '㏑'
    let g:airline_symbols.branch = '⎇'
    let g:airline_symbols.paste = 'ρ'
    let g:airline_symbols.paste = 'Þ'
    let g:airline_symbols.paste = '∥'
    let g:airline_symbols.spell = 'Ꞩ'
    let g:airline_symbols.notexists = 'Ɇ'
    let g:airline_symbols.whitespace = 'Ξ'

    " powerline symbols
    let g:airline_left_sep = ''
    let g:airline_left_alt_sep = ''
    let g:airline_right_sep = ''
    let g:airline_right_alt_sep = ''
    let g:airline_symbols.branch = ''
    let g:airline_symbols.readonly = ''
    let g:airline_symbols.linenr = '☰'
    let g:airline_symbols.maxlinenr = ''

Kitchen sinking the fonts on Fedora and Ubuntu

This is probably an overkill solution, but first you need to get it consistently working before you can simplify it.

  1. Install the general powerline font sudo dnf install powerline-fonts (or sudo apt install fonts-powerline) - this should mean that you can use any font you already have installed. If you don't have an easy way of installing like dnf/apt then there's instructions for manually doing it e.g. https://www.tecmint.com/powerline-adds-powerful-statuslines-and-prompts-to-vim-and-bash/, also the official documentation has instructions (https://powerline.readthedocs.io/en/latest/installation/linux.html#fonts-installation).

    Now close your terminal re-open and check that the Powerline symbols font is available if you edit the terminal preferences and set a custom font. You don't want to use the font directly, just check that it's available. Now try opening Vim and see if you have nice symbols.

  2. If the general powerline font didn't work or if you're trying to improve things you can try installing individual 'patched' fonts, this took a while to figure out, but you can literally just go to the folder you want in https://github.com/powerline/fonts/ and download it, the font that I've liked the most from my tests is the Source Code Pro patched font. Then just open the downloaded font file and click on 'Install'.

    If you'd rather the command line, you can install all patched fonts:

    $ git clone https://github.com/powerline/fonts.git --depth=1
    $ fonts/install.sh
    $ rm -rf fonts
    

    This will install all the patched mono fonts, but then this gives you a chance to explore the possible fonts. The font list it installs is a pretty awesome list of the available source code fonts. It also means you don't have to faff around installing each of the individual fonts that get included.

  3. Check that the font can be specified in the terminal preferences, re-open your terminal session if you're missing fonts, so note there could be two options here:

    1. The general powerline font is working in which case you can just use the base font e.g. DejaVu Sans Mono
    2. If you can't get that working the patched font that you downloaded above should be correct e.g. the equivalent for DejaVu is 'DejaVu Sans Mono for Powerline'.

Handling the delicate flower of Windows

The Powerline Fonts doesn't work with Windows so your only choice is to use a patched font. Also bash script to install all the fonts doesn't work. This means that on Windows you manually have to go into each of the fonts directories and download all the fonts yourself and install them by opening each one in turn.

I downloaded all of the Source Code Pro patched fonts and installed them. Even though you install them as individual fonts they get added to Windows as a single font 'Source Code Pro for Powerline' with a separate attribute to specify the weight.

Then add this to your .vimrc:

set guifont=Source\ Code\ Pro\ for\ Powerline:h15:cANSI

If you want to use the 'Light' font use this.

set guifont=Source_Code_Pro_Light:h15:cANSI

It doesn't make much sense as it doesn't need to include the 'for Powerline', but that's how it works (I figured it out by setting the font in GVim and then using set guifont? to check what GVim used). Also I spotted that when you use GVim to switch the font, the font rendering isn't very good. I initially discounted the Light font because when I switched using the GVim menu it rendered badly, but if you put the below into your .vimrc and restart GVim it should look lovely.

Also the nice thing is that you can set your DOS/Powershell prompt to the same font.

Tweaking

Once I actually got it working for the first time, it was really disappointing as the icons didn't fully match up. But as per the FAQ we need to do some tweaking. I started off with Inconsolata as this gives me a consistent font across Windows and Linux. You can install the general font easily on Ubuntu with apt install fonts-inconsolata This is what I got:

enter image description here

The arrows are too large and are shifted up in an ugly manner.

Then I tried all the other default Ubuntu fonts.

Ubuntu mono:

enter image description here

DejaVu Sans Mono:

enter image description here

This has the vertical position correct but the right hand side arrows have a space after them.

Why you use the patched fonts

Using the default fonts relies on the Powerline font to automatically patch existing fonts. However you can improve the look of the airline symbols by using the patched fonts. These are the equivalents using the patched fonts.

I display these all at font size 16 as I like to use a larger font, plus it shows up minor issues.

Inconsolata for Powerline:

enter image description here

This still has issues, but they are almost all solved by the dz variation.

Inconsolata-dz for Powerline dz:

enter image description here

This has a hairline fracture on the right hand side arrows, but is otherwise perfect.

Ubuntu Mono derivative Powerline Regular:

enter image description here

This still has annoying issues.

DejaVu Sans Mono for Powerline Book:

enter image description here

This has a hairline fracture on the right hand side arrows, but is otherwise perfect. I actually prefer it to the Inconsolata-dz as the LN icon is more readable.

On top of these regulars, I tried almost all the available fonts and my other favourite was Source Code Pro.

Source Code Pro for Powerline Medium

enter image description here

This does have issues at size 16 where the arrows are too big, but at size 14 it's almost unnoticeable. The branch and LN icons do overflow to the bottom, but somehow this doesn't annoy me.

Source Code Pro for Powerline Light

enter image description here

This almost completely solves the issues of the medium font's arrow sizes and makes it about perfect, although there's still the icon overflow.

Source Code Pro

When I was investigating the options for fonts there's a couple of things you notice, some font patches have the absolute minimum in details, if you compare this to the Source Code Pro list it's quite significant. Source Code Pro is a very detailed and complete font that has been considered to work in a large range of scenarios. This kind of completeness matters for edge cases.

Used as a patched font it almost perfectly displays the vim-airline bar. The benefit of so many alternatives is the use of the light font which has an even better display of the vim-airline bar.

Source Code Pro is also under continued open development on Adobe's Github repository.