87

I installed the Airline plugin in order to have a custom status bar, as seen in the figure below:

Enter image description here

However, my status bar is presenting the symbols <, >> and <. How do I fix this problem?

Enter image description here

Enter image description here

Enter image description here

Geison Santos
  • 989
  • 1
  • 7
  • 7
  • Use https://everythingfonts.com/otf-to-ttf to convert the fonts to ttf, Example: Older XShell Versions doesn't support otf. – JaDogg May 25 '15 at 14:57
  • For maximum compatibility I leave airline_powerline_fonts off. I don't think they are really that useful. – qwr Oct 18 '19 at 22:51

4 Answers4

70

At first I too didn't understand what needs to be done to get this nice looking toolbar. Yes I know about the README and other stuff, but I think there should be a getting started or minimum settings section in the help file.

Anyway here are the settings.

Installing the appropriate fonts

You need to install fonts into your system with symbols like branching, big triangles etc. They are not standard symbols so you need to install a patched font. You can find a lot of patched fonts here: https://github.com/powerline/fonts.

.vimrc settings

From :help airline-customization, place this code into your .vimrc file:

" air-line
let g:airline_powerline_fonts = 1

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.linenr = '␊' let g:airline_symbols.linenr = ' ' let g:airline_symbols.linenr = '¶' let g:airline_symbols.branch = '⎇' let g:airline_symbols.paste = 'ρ' let g:airline_symbols.paste = 'Þ' let g:airline_symbols.paste = '∥' let g:airline_symbols.whitespace = 'Ξ'

" airline 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 = ''

The unicode symbols section is unnecessary here if you already have a patched font but it gives you a nice fallback if you try to use other font which doesn't have the appropriate symbols.

Font settings

If you use Vim in terminal you should switch to the appropriate font in profile preferences of your terminal.

If you use gui version of Vim (MacVim, GVim) you need to set the font in .vimrc, for example: set guifont=DejaVu\ Sans:s12. You can find more information here :help guifont.

guntbert
  • 1,245
  • 1
  • 13
  • 27
Alexander Myshov
  • 2,118
  • 15
  • 18
  • 1
    Hello, Alexander. I followed his instructions, but still can not get the expected result: at first installed the fonts from the site of the powerline. Then I made the settings in the .vimrc file. My .vimrc file has been shared in https://gist.github.com/geisonsn/641f13543b8b41fe2c12. I'm using Vundle manager plugin. – Geison Santos May 22 '15 at 15:58
  • Did you install that font in your editor? If you use vim in terminal you should install that font in the terminal, or if you use gui-version of vim (MacVim, GVim) you need to set font in the .vimrc-file, for example: set guifont=DejaVu\ Sans:s12. More information you can find here :help guifont. – Alexander Myshov May 22 '15 at 17:05
  • Alexander, thank you for your help. I configured the fonts in gnome-terminou and it work. Would you can add this suggestion in your answer? – Geison Santos May 22 '15 at 20:00
  • You are welcome! Answer is updated. – Alexander Myshov May 22 '15 at 20:18
  • 2
    @AlexanderMyshov you have repeated configuration lines, where only the second in every two is required. – Vitor May 23 '15 at 02:06
  • 1
    Just created an account here at vi.stackexchange to thank you and upvote this wonderful answer of yours. Thank for relieving me thousand searches. – 0decimal0 Aug 30 '15 at 19:54
  • @AlexanderMyshov I have installed patched font locally (which, could be used by gvim and other applications), and everything is ok with my gvim, however when I use a terminal (it's mintty.exe that came along with cygwin and already configured to use that patched font) to use vim in SSH on a remote Linux machine, those nice looking symbols could not be displayed correctly, so I'd like to know what you mean about "install that font in the terminal...". – j5shi Apr 28 '18 at 07:02
  • @j5shi I meant that in terminal emulators usually there are some settings that allow you to choose appropriate font. So if you choose in settings of mintty patched font then everything should be fine. However if in your case there are some problems you should research about unicode support in your terminal emulator probably... – Alexander Myshov Apr 29 '18 at 13:05
  • 2
    I think there should be a getting started or minimum settings section... I don't know if it will get deleted or not, but I've added a Dummies Guide to the vim-airline wiki based on my answer. – icc97 Jun 18 '18 at 11:42
  • @Vitor these settings just come straight from the help guide. It may be that the help guide needs to be improved, I agree they are confusing and do seem like overkill. But at least they work people can then tweak them as they see fit. – icc97 Oct 10 '18 at 10:28
  • 1
    @AlexanderMyshov You set let g:airline_left_sep, let g:airline_right_sep, let g:airline_symbols.branch nad let g:airline_symbols.linenr twice... I think only the later prevails and the former is lost... – 71GA Apr 02 '20 at 06:42
  • Yes, you are right. The point is to present alternatives for choosing among different symbols. But I will appreciate if you will fix the answer with the better way to convey that idea. – Alexander Myshov Apr 04 '20 at 18:15
16

From the README:

Integrating with powerline fonts

For the nice looking powerline symbols to appear, you will need to install a patched font. Instructions can be found in the official powerline documentation. Prepatched fonts can be found in the powerline-fonts repository.

Finally, you can add the convenience variable let g:airline_powerline_fonts = 1 to your vimrc which will automatically populate the g:airline_symbols dictionary with the powerline symbols.

lcd047
  • 3,700
  • 16
  • 26
  • 1
    I found that let g:airline_powerline_fonts = 1 wasn't enough. For some reason this still didn't automatically populate the g:airline_symbols, so I had to manually populate the dictionary as per Alexander Myshov's answer. – icc97 Jun 17 '18 at 16:35
12

This took hours to figure out, so here's more of a dummies guide for Fedora/Ubuntu, with a special section for Windows. I've created duplicates of this on my own blog and in the GitHub Airline Wiki.

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.

.vimrc settings

The final trick was forcing vim-airline to use the symbols it needs. Copy and paste the settings mentioned in Alexander Myshov's accepted answer here.

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. This was the final magic sauce that I needed. I don't know why this wasn't automatically created.

This is opposite to the official instructions but I had this bit wrong 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.

There's more information in :help airline-customization and that gives you some simple config settings that you need, just in case.

Kitchen sinking it 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'.

Tweaking Linux

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.

Handling the delicate flower of Windows (assuming GVim)

The Powerline Font doesn't work with Windows so your only choice is to use a patched font. Also the bash script to install all the fonts doesn't work, so you have to do the same git clone but then go into each of the individual directories and install the fonts you want.

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 (assuming GVim) 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 a nice thing is that you can set your DOS/Powershell prompt to the same font. Then with the patched font it is also possible to get Powerline working in regular Vim within DOS.

If you don't believe me, here it is working in Vim in Powershell:

enter image description here

enter image description here

icc97
  • 583
  • 1
  • 6
  • 16
  • 1
    This gave me the inspiration to try it on my own. Thanks. I finally settled for what I already had + "for Powerline" (DejaVu Sans Mono for Powerline Book). Not perfect but good enough. What made me take the step is an update of airline that made a mess with non-mono "heaven trigram". I did not really need the neat arrows, but the standard status patterns are really designed for the Powerline symbols. So now, my problem is fixed and I get the cool status line. Nice, I guess... – nilo Mar 15 '23 at 23:14
  • 1
    On Ubuntu, fully closing all terminals seemed to be necessary to make it actually load the new font. – twhitney Jan 26 '24 at 18:02
5

I had the same issue after reinstalling Vim: my old patched fonts were not compatible with the new airline symbols.

The old symbols are also mentioned in the help (:help airline-customization):

" old vim-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: '⭠', readonly: '⭤', linenr: '⭡'}

After I put these lines in my vimrc everything went fine.

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
Mattia72
  • 191
  • 2
  • 6