Vim Airline Powerline fonts on Fedora, Ubuntu and Windows

N.B. I’ve also answered this on Vi Stack Exchange, but I’m posting it here as it took a lot of work.

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.

Configuring Vim

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.

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 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’.

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.

Installing Haskell ++ Emacs on Windows

Haskell

Firstly install the haskell-stack chocolatey package:

choco install -y haskell-stack

For me that perfectly installed haskell and meant that I could run stack commands and have stack ghci running in a DOS prompt.

Emacs

Chocolatey has an Emacs package:

choco install -y emacs

This puts the emacs binaries into the chocolatey bin directory. Then the .emacs file and the .emacs.d directory go into %APPDATA%.

This installs an Emacs windows program. I wondered if there was a DOS version similar to Vim. There is an Emacs For DOS – but this isn’t part of the Chocolatey package, which comes from the GNU Emacs FTP directory.

Intero

The haskell project have a new integration with Emacs. I have to say this installed remarkably easy. The only problem I had was that I’d put a bad config into %APPDATA%\stack\config.yaml and this created errors – that were well explained in Emacs.

It’s not 100% clear how you get things to work though. Bare in mind I’ve never used Emacs before today.

I have managed to get Haskell setup and working, which came with stack.

Following the Intero guide, the installation of the package was easy enough – just edit the %APPDATA%\emacs.d file. I restarted Emacs and the Intero package installed itself without errors.

Following the guide further I ran the stack new intro-demo command in a directory. This created the intero-demo directory and put everything in it. If you then ‘File > Open Directory’ in Emacs to open the intero-demo directory. Opening Setup.hs had the affect of getting Intero to install itself.

At this point things were actually working – but it wasn’t obvious the the error as you type checking was happening because it was erroring at the very first command of the Setup.hs

However if you open up a new Haskell file in the directory it should start doing error checking on the fly.

Jupyter on Windows with Chocolatey

Install Python

This is a quick post (and will probably be outdated quickly), but it took me a while to get it correct.

I wanted to install Jupyter on Windows. The recommeded route is via Anaconda but I like to use Chocolatey the Windows package manager as much as possible.

I used Chocolatey to install Python package (currently v3.5.1). Assuming you’ve installed Chocolatey already, run as administrator:

choco install -y python

This installs python to C:\Program Files\Python35. It also installs and pip.exe to C:\Program Files\Python35\Scripts.

Add C:\Program Files\Python35 and C:\Program Files\Python35\Scripts to your PATH then you should be able to run python and pip immediately.

Install PIP (hint: it’s already installed)

Note that pip gets automatically installed when you install python – nothing extra is required.

You can get led astray here by an official guide which suggests having to download and run ez_setup.py.

Don’t do this.

There is also confusingly a Chocolatey PIP package. Again don’t install this.

Otherwise you might end up here.

Running PIP packages

Because we’re using Chocolatey, the installation doesn’t follow the recommended installation for Jupyter.

The main thing is that you need to add the python Scripts directory to your PATH, as above.

Install Jupyter

Run as administrator:

pip install jupyter

This will install a jupyter.exe file into the Scripts directory. If that directory is in your PATH, then you should be able to directly run jupyter commands.

Create a Jupyter notebook

Jupyter runs inside the browser but installs files and all the save data in the directory that you run the jupyter command from.

mkdir jupyter
cd jupyter
jupyter notepad

If everything is working that will open up your browser at http://localhost:8888/.

Dos command history

One of the nice things of Linux is the command history – it stores typically the last 1000 commands or so and its saved every time you log out.

DOS does have this through the doskey /history command (but only for current session) and you can relatively easily append this to a file:


doskey /history >> %USERPROFILE%\history.txt%

view raw

doskey.bat

hosted with ❤ by GitHub

The tricky bit is having this done for you on log out.

Via a Stack Overflow question on bash_history you can get close, using doskey macros which appends to a file on exit.

This only works for the current session though so you need to create a shortcut that runs the command each time with the following Target:


%windir%\system32\cmd.exe /K doskey exit=doskey/history$g$g%USERPROFILE%\history.log$texit $1 $2

Then you just have to remember to type exit each time…

Shortcut target
Shortcut target

Update

I also found three useful commands – but they’re only for your current session. Hat tip to Nifty Computer Tricks:

F3
get last command
F7
current list (use left/right arrow keys to paste to the command line)
F8
auto-complete (type the first few letters)

Update 2 – Some extra love for the DOS prompt…

If you’ve got this working then I’ve added some extra basics. First you need to install Git (and I suggest you do it using the Chocolatey package). This includes the best versions of gnu commands compiled natively for Windows.

Add the Git usr bin directory to the path e.g. C:\Program Files\Git\usr\bin.

Then download my !.bat / history.bat gist:

Put the !.bat and history.bat into the Git usr bin directory too. These assume you are saving the history to %USERPROFILE%\history.log.

Then you’ll be able to do commands like history | grep mysql to list all your mysql commands in history.log with their line numbers. Then call ! 123 to execute the specific line of the history.log file.

Update 3 – Clink love

Martin Ridgers’ Clink is an awesome tool to behold. That adds the correct ! command to the DOS command prompt. Buuuuuuut… it doesn’t include a history command. So save the above history.bat file to C:\Windows\System32\history.bat (it doesn’t have to rely on GNU Tools / Git) and uncomment history_file=%localappdata%\clink\.history.


@echo off
rem simple replacement for linux ! syntax e.g. !591
rem usage: ! N (executes line N of history.log)
rem @link http://ianchanning.wordpress.com/2014/10/29/dos-command-history/
if "%1"=="" goto Syntax
if "%1"=="/?" goto Syntax
for /f "tokens=*" %%x in ('sed -n "%1{p;q}" %USERPROFILE%\history.log') do echo %%x & cmd /c %%x
goto End
:Syntax
echo usage: ! N
:End

view raw

!.bat

hosted with ❤ by GitHub


@echo off
rem replacement for linux `history` command
rem usage: history
rem @link http://ianchanning.wordpress.com/2014/10/29/dos-command-history/
set history_file=%USERPROFILE%\history.log
rem For if you are using Martin Ridgers 'clink'
rem @link http://mridgers.github.io/clink/
rem set history_file=%localappdata%\clink\.history
rem this doesn't require GNU Tools, but doesn't have line numbers
rem type history_file
rem requires GNU Tools installation (e.g. Git SCM)
cat -n %history_file%

view raw

history.bat

hosted with ❤ by GitHub

OpenVPN connects to VPN but no internet

For those stumbling down a similar path…

tldr; Check that your Windows Firewall is turned off.

My setup

  • OS: Windows 8.1 64-bit laptop
  • OpenVPN: OpenVPN 2.3.4 x86_64-w64-mingw32

My OpenVPN has been working for at least 4 months without problem.

First thing to remind yourself is: When you get the VPN working – copy the OpenVPN log of a successful connection and the ipconfig /all to file so that you know what to compare when it breaks next time.

Notes

  • The VPN connection stopped working yesterday 17/10/2014
  • Not exactly sure when
  • It had been working at my office
  • My Windows 7 desktop has a working VPN setup so I can compare the settings
  • The OpenVPN gui suggests a connection has been made but no sites can be pinged (see commands below)
  • All attempts at inconfig /renew, ipconfig /flushdns nothing worked
  • Only differences between Desktop/Laptop I could find in ipconfig /all and OpenVPN logs was that laptop had IPv6 for the WiFi connection turned off and the following extra fail message UDPv4: No Route to Host in the log
  • I tried turning IPv6 back on but that didn’t change anything
  • Now the UDPv4 message disappeared – but didn’t reappear when I turned off IPv6 again – so that was a red herring
  • Possible suggestion from my history when first setting up my VPN (http://www.rickygao.com/troubleshooting-general-failure-in-ping-or-tracert/) was to turn off IPv6 which is what I’d probably done before – but IPv6 is no problem on my Windows 7 desktop
  • Pinging even a specific IP address does not work – this confirms its not a DNS issue
  • Pinging localhost 127.0.0.1 does work
  • Pinging the IP Address of the connected VPN does work
C:\Users\Ian>tracert google.com
Unable to resolve target system name google.com.

C:\Users\Ian>ping google.com
Ping request could not find host google.com. Please check the name and try again.

Solution

Eventually found a solution that was to turn off the windows firewall, which came from this unbuntu forums post which eventually spotted that it was an iptables firewall issue.

Post mortem

  • I thought I’d turned off my firewall and it doesn’t explain why the VPN stopped working
  • Best guess is a Windows update changed something in the firewall the caused the problem
  • The only Windows updates I received on 17/10/2014 were
  • A failed update for Windows Malicious Software Removal Tool for Windows 8, 8.1 and Windows Server 2012, 2012 R2 x64 Edition - October 2014 (KB890830) – this was successfully installed the next day but didn’t help
  • A successful Definition Update for Windows Defender - KB2267602 (Definition 1.185.3528.0)

Windows Netbeans Composer notes

This is for installing the main packages that Netbeans suggests in the Tools > Options > PHP (tab)

I’m running the following setup currently [21st April 2015]:

  • Windows 8.1 (64-bit)
  • Netbeans 8.0.2
  • The version of Composer doesn’t really matter
  • PHP 5.3.28 (It’s sooo last decade, I know…)

tldr;

Just the commands:

composer global require "phpunit/phpunit=4.6.*"
composer global require "phpunit/phpunit-skeleton-generator=*"
composer global require "squizlabs/php_codesniffer=*"
composer global require "phpmd/phpmd=@stable"
composer global require apigen/apigen:~2.8

Then the files to call are in C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\

Global packages

running composer global installs the packages into %APPDATA%\Composer (or ~/.composer/ in Linux)

PHPUnit

From the installation instructions (https://phpunit.de/manual/current/en/installation.html) do:

composer global require "phpunit/phpunit=4.6.*"

This installs PHPUnit to C:\Users\[username]\AppData\Roaming\Composer\vendor\phpunit and puts the binary to use in Netbeans in C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpunit.bat

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpunit.bat into Netbeans Tools > Options > PHP (tab) > Frameworks & Tools (tab) > PHPUnit section.

Skeleton Generator

From the installation instructions (https://github.com/sebastianbergmann/phpunit-skeleton-generator) run:

composer global require "phpunit/phpunit-skeleton-generator=*"

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpunit-skelgen.bat into Netbeans Tools > Options > PHP (tab) > Frameworks & Tools (tab) > PHPUnit section.

PHP_CodeSniffer

composer global require "squizlabs/php_codesniffer=*"

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpcs.bat into Netbeans Tools > Options > PHP (tab) > Code Analysis (tab) > Code Sniffer section.

Mess Detector

composer global require "phpmd/phpmd=@stable"

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\phpmd.bat into Netbeans Tools > Options > PHP (tab) > Code Analysis (tab) > Mess Detector section.

apigen

composer global require apigen/apigen:~2.8

For me this failed see apigen issue #316. The answer to that was to use ~4.0, but that requires PHP >= 5.4

Then put C:\Users\[username]\AppData\Roaming\Composer\vendor\bin\apigen.bat into Netbeans Tools > Options > PHP (tab) > Code Analysis (tab) > ApiGen section.

ntwdblib download

For years I have had problems running the mssql driver. Its getting phased out – i.e. it doesn’t work with PHP 5.3 but if you have to support older applications then you need to use the mssql driver. The problem is, is that the default installation of PHP 5.2 (currently PHP 5.2.17) which you can download from http://windows.php.net just doesn’t work with the mssql driver.

The problem is the ntwdblib.dll. The version that has always worked for me is 2000.80.194.0 – all others fail. The version that comes with the PHP msi installer (I use the 64 bit installer) is version 2000.80.2039, which should in theory be newer and work better. So each time I install PHP I then have to go in and overwrite the dll.

The next problem you have is finding a reliable dll. The proper way to get it is from the SQL Server 2000 SP4 installation (yes, the file is that old). If you google for the file there’s no pages that I find that seem a trust worthy resource for this file.

So I’ve uploaded the file to my site n.b. its a different site from this WordPress blog as I doubt WordPress.com will allow me to upload dlls.

Download

Installing Ubuntu on Windows

It really is getting quite easy to install Ubuntu onto a computer from Windows now – especially if you’re not trying to Dual-boot. But if you do want to Dual boot, you’d still do the following but you have to partition your hard-drive first (which is remarkably tricky).

Installall Ubuntu onto a USB stick

UNetbootin is your friend

Here’s the main Ubuntu document: https://help.ubuntu.com/community/Installation/FromUSBStick#From_Windows

  1. Plug-in an empty USB stick
  2. Download UNetbootin (http://unetbootin.sourceforge.net/) & Install
  3. Run UNetbootin
  4. Distribution: Ubuntu | Type: USB Drive
  5. Click OK – wait for the download and the installation
  6. Either Reboot when asked or click close and remove the USB stick

Install Ubuntu from USB-stick onto your computer

  1. Set the computer to boot via USB, if you don’t know how, search Google for: [Your computer make & model] usb boot
  2. Turn off the computer
  3. Insert the USB stick
  4. Turn on
  5. Click Install Ubuntu