Lee Packham

Software Engineer, UX Designer, Opinionated

VIM All the Things - Part One

I probably spend way too much time configuring my VIM setup. It tends to change depending on what I’m working on. So, at the moment the following things matter to me most:

There would be Scala, but I use the excellent IntelliJ IDEA product for that. Nothing can beat it, so there’s no point trying to get VIM to do it.

It matters to me that my editor works cross platform too. Not fussed so much about VIM on Windows (although it’s nice when that works too) but more between OSX and Linux as they are the main two Operating Systems I use.

So I felt I’d do a post about how I manage my VIM config as it may/may not be useful for others.

Setup

Let’s start nice and empty:

1
2
3
4
5
mv ~/.vim ~/.vim.old
mv ~/.vimrc ~/.vimrcold
mkdir ~/.vim
touch ~/.vim/myvimrc
ln -s ~/.vim/myvimrc ~/.vimrc

Why do this? Well, simply put - this way your .vim folder can be easily stored in Git or another VCS you fancy. Job done!

Right, so what next? vundle all the things.

1
2
mkdir ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/vundle

Now you need a small bit at the top of your .vimrc file.

1
vi ~/.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()"

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" Your stuff is going go here...

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

Now we have a basis of a working VIM we can work on. Let’s set up some cool stuff now…

Some obvious bootstrap things

By default, VIM likes to behave a little bit old fashioned. We want some niceties from the off - so let’s do that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
set expandtab     " Soft tabs all the things
set tabstop=2     " 2 spaces is used almost everywhere now
set shiftwidth=2  " When using >> then use 2 spaces
set autoindent    " Well, obviously
set smartindent   " As opposed to dumb indent

set noautowrite
set number
set autoread      " Read changes from underlying file if it changes
set showmode      " Showing current mode is helpful++
set showcmd
set nocompatible  " Actually make this vim
set ttyfast       " We don't use 33.6 modems these days
set ruler

set incsearch     " Use incremental search like OMG yes
set ignorecase    " Ignore case when searching
set hlsearch      " Highlight searching
set showmatch     " Show me where things match
set diffopt=filler,iwhite "Nice diff options
set showbreak=" Cooler linebreak
set noswapfile    " It's 2014, GO AWAY FFS

set esckeys       " Allow escape key in insert mode
set cursorline    " Highlight the line we're on
set encoding=utf8 " Really, people still use ASCII

You’ll notice that 2 spaces is the default but, obviously, Python is a good example of a language that uses 4.

1
au FileType python setlocal tabstop=8 expandtab shiftwidth=4 softtabstop=4

This way you’ll see, we get to customise each language. It’s nice. ‘au’ is short for auto. As in… Automatically run this when the FileType is python.

Syntastic

This is the Batman utility belt. It’s also easy to set up and serves as a good example of how Vundle works.

1
Bundle 'scrooloose/syntastic'

Job done. Make sure this goes between the Vundle begin and end calls.

Now save that and we’ll online reload/install:

1
vim -c "execute \"BundleInstall\" | q | q"

This will load up vim, install all the things and then exit when done.

Part One Done

I was going to write this in one post - but I changed my mind when this started taking a lot longer to write than I wanted.

Next part, I’ll focus on setting Syntastic with Python and how to make vim-go the setup you want for managing Go projects.

FOSDEM 2014

Just spent the weekend at FOSDEM 2014. It’s the first time I have been to FOSDEM and checked out more of the Open Source world.

Seven of us went from Green Man Gaming and the only thing I will remember for the future is that I need to turn up to talks I want to go to very much in advance.

Rooms were always very quickly packed out. Managed to meet lots of cool and awesome people though.

Go was the language of the conference

There’s no way you could avoid this. Go is mainstream now. It’s been heading this way for a while - but it’s very clear that this language that people wondered the point of is now relevant to the point of obsession. The room was constantly ram packed and people staying for talk after talk.

I’m not the only one that laughs at MongoDB

Yep, turns out lots of people find the stability amusing.

There tons of PostgreSQL I don’t know

This was always going to be a given. The RDBMS is still relevant and still attracting a lot of attention. There was a definite lack of MySQL and MariaDB however. Maybe that swings it a bit.

There’s loads of stuff coming in 9.4.x for JSON and the like. The main thing I got from the talks though was an understanding of TOAST.

I need to do more here

Next year… I need to make more of an effort to plan and attend more talks.

I will be here next year!

Making HTTP Client Calls With Finagle

I was trying to make HTTP calls using Finagle today and all I would get was this traceback from my logs:

1
2
3
4
5
6
7
8
9
10
11
12
13
FAT [20121215-15:49:46.803] HttpServer: A server service client threw an exception
FAT [20121215-15:49:46.803] HttpServer: com.twitter.finagle.WriteException$$anon$1: java.net.ConnectException: connection timed out
FAT [20121215-15:49:46.803] HttpServer:     at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processConnectTimeout(NioClientSocketPipelineSink.java:391)
FAT [20121215-15:49:46.803] HttpServer:     at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:289)
FAT [20121215-15:49:46.803] HttpServer:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
FAT [20121215-15:49:46.803] HttpServer:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
FAT [20121215-15:49:46.803] HttpServer:     at java.lang.Thread.run(Thread.java:722)
FAT [20121215-15:49:46.803] HttpServer: Caused by java.net.ConnectException: connection timed out
FAT [20121215-15:49:46.803] HttpServer:     at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processConnectTimeout(NioClientSocketPipelineSink.java:391)
FAT [20121215-15:49:46.803] HttpServer:     at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:289)
FAT [20121215-15:49:46.803] HttpServer:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
FAT [20121215-15:49:46.803] HttpServer:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
FAT [20121215-15:49:46.803] HttpServer:     at java.lang.Thread.run(Thread.java:722)

It turns out I needed to set up my ClientBuilder a little differently:

1
2
3
4
5
6
7
  val client = ClientBuilder()
    .codec(Http())
    .hosts("localhost:80")
    .tcpConnectTimeout(2.seconds)
    .requestTimeout(55.seconds)
    .hostConnectionLimit(5)
    .build()

The important bits, that don’t appear well documented are tcpConnectTimeout and requestTimeout. The normal ‘timeout’ usually used on the ClientBuilder is not what you want.

This was more a note for me - but figured people Googling might find it useful also.

Write Code Like You Mean It

Recently I was catching up on talks from DjangoCon EU 2012. Wish I could have been there. This talk on Flasky Goodness (or, why Django sucks) sort of rang a bell with me.

Why? Well, for me the point of writing everything like it’s going to be open source seems like a great way of doing things. It’s a great philosophy to have. Seriously.

Don’t Bother With That Degree, Say IT Pros

Interesting tidbit posted by The Register last week. It’s a topic fairly close to my heart as I don’t have a degree. I do, weirdly, get asked about this quite a bit - “should I get a degree?”. If you think you should, you should. Don’t let any “IT pro” sway your decision.

This is especially important now that degrees are just so damned expensive. According El’Reg, you’re looking at £27k for your degree. Wow!

Personally, when I look at people’s CVs, the first thing I’ll do is Google them. Then, I’ll take a look at their Github profile. Then I look at their education. It’s important that if they did a degree, they did well - but it doesn’t matter if they didn’t do one at all.

Git: Squashing Commits Without Merging a Thing

This trick has saved me today and I’ve had to use it before… so I’m going to demonstrate how to do this here in my own words to save me Googling for every time!

So imagine the scenario. You’ve done a load of commits and you’re not ready to merge them back into master (or, even worse you’re in master) and you realise you made a massive mistake a few commits back and you need to just squash all the correction commits into it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
commit 6e0fa1b21e760aee2391f73c4905244a229abe8b Author: Lee Packham
<xxx> Date: Sat Jul 2 12:47:31 2011 +0100

More tidy up (I'm a muppet)

commit abe08fd948f81f3366bc9a647e0d0c24ffe5fdc6 Author: Lee Packham <xxx>
Date: Sat Jul 2 12:46:14 2011 +0100

Tidy up

commit caefc1c0a8903009af2be8cd37df1ac40366fcce Author: Lee Packham <xxx>
Date: Sun Jun 19 08:21:03 2011 -0700

Initial commit

Well that’s crap really isn’t it? So how do we go about sorting this? Well, we make a good use of rebase and tags to achieve this. There’s a nice answer to this on Stack Overflow - but I’ll replay it here. Props to Charles Bailey for this process.

So, here’s how we fix this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Checkout the top commit in a detached branch git checkout
6e0fa1b21e760aee2391f73c4905244a229abe8b

# Now, do a soft reset back to the original commit git reset --soft
caefc1c0a8903009af2be8cd37df1ac40366fcce

# Now commit --amend it to squash it all git commit --amend

# Then, tag this new detached commit git tag tmp

# Now go back onto master git checkout master

# Awesome now do a quick rebase and it'll replace the upstream with tmp git
rebase --onto tmp 6e0fa1b21e760aee2391f73c4905244a229abe8b

# No need for tmp now git tag -d tmp

Not overly simple - but brings, in this case, master to where I wanted it to be!

Making Qt Webkit and Macdeployqt Work

When making a Webkit app with Qt, bundling a .app will not work. Ok, so that’s not quite true - but it won’t run. This is a build bug on the Qt side - fixable with a small post-bundle step:

This will mean your app will no longer crash - so fairly useful.

Moved Domains for the Blog

I got bored of leenux.org.uk as a domain name. So I’ve moved everything to leecutsco.de - I think it looks cooler - and also leenux was only bought as a joke. I’m a sucker for domain names… I actually own over 20. The annual bill for that is redonkulous (grr @helenmoyes has me addicted to that word now).

I’ve kept my e-mails the same, for now, however - leenux.org.uk has been my primary domain for nearly a decade (10 years this November), so I’ll have to keep it running regardless. This’ll just be the blog for now.

TweetDeck Joins the Twitter Flock

The last week has been, as I’m sure you can imagine, hectic. It’s all out the bag now - TweetDeck has been acquired by Twitter. It’s absolutely amazing news and I’m really proud to be a part of it. As part of the deal, my employment, along with the entire team, has transferred over to Twitter.

I came along fairly late in the day in all this having only joined in January of this year. I never guessed that by now I’d be working for Twitter as a Software Engineer. I’m totally stoked.

I’ll still be working on mobile clients - and hopefully I’ll get more time to work on Chrome hacks.

So, congratulations everyone! Special congratulations to Iain… it proves that scratching an itch really can lead you down paths you never expect. Let this be a lesson to Software Engineers / Programmers everywhere.