Category Archives: tools

setting up vim on windows

So you want to make the plunge and check out what that awesome Vim editor is all about on a Windows machine? I did about a year ago, and this time I actually stuck with it. I tried it 2 times before already, but I gave up every time after a few hours or days because of the steep learning curve and the fact that nothing seemed to work the way I’m used to.

The goal here is to get Vim set up on a Windows box, make it work like a Windows app and make it look like something you aren’t afraid of being seen with (that default layout, euhm, seriously…).

installing Vim on Windows

The easiest way to install gVim (the non-console version) on Windows is by using the Vim Chocolatey package. It installs the Cream Windows flavored Vim for you from Sourceforge and sets up your system path so you can run “vim” and “gvim” to start the editor from the command line if you want to.

Chocolatey itself is like apt-get for Windows. It’s a NuGet based software package manager and if you’re a software developer or have to install systems a lot, I’m sure you’ll love it.

To install using Chocolatey, type this from a command shell (run in administrator mode):

    choco install vim

Easy isn’t it?
If you really don’t want to setup Chocolatey (but you should really) you can also get the Windows binaries from vim.org, or the Cream ones. You’ll get the Cream editor with that based on Vim, but I didn’t want that cause it’s not quite pure Vim anymore (not modal for example).

first steps

Before you start configuring Vim you should start with getting to know it. Whatever comes next will be a lot easier once you know how to move around, save files etc. You know, those typical things you do in a text editor anyway.
So basically you have to RTFM. Or at least, the short version of it.

Find the Vim tutor in your start menu and run it. Once you’ve completed that, you know enough to get around in Vim and find out how to get help for other stuff. Also, don’t bother with doing it the hardcore way. Just learn Vim at your own pace, use the cursor keys and the mouse if you want. You’ll pick up more advanced stuff as you go along.
Just like this guy said.

configuring Vim

Vim uses vimrc configuration files to store settings. There is a default vimrc file in your Vim installation folder, but you shouldn’t touch that one because it can be overwritten when you install a Vim update. Your own settings go into a new _vimrc file containing only the things you want. You can “source” or include other vimrc files, to avoid duplication or organize your configuration.

On a Windows machine this goes into your user folder (c:\users\username\_vimrc).

To see and edit your current vimrc (the one use by vim when it starts) type:

    :edit $MYVIMRC

Once you’ve created your own config file, the above command will automatically open it. So let’s do just that, like this. “e” is short for “edit” btw:

    :e ~\_vimrc

That tilde character (~) stands for the path to you home folder, which on Windows is normally set to c:\users\<username>.

On Windows the folder  ~\vimfiles is used to store custom plugins. I put my vimrc in ~\vimfiles and source it from the ~\_vimrc file. That way I easily sync my whole setup to another machine by simply copying the whole vimfiles folder. So my ~\vimrc file contains only this line.

source ~\vimfiles\nj-vimrc.vim

You can keep everything in _vimrc of course if you want.

You can test Vim statements from the command bar before you put them in your vimrc file. A handy way to test and see if it really does what you want it to without having to restart Vim and reload your configuration.

making Vim behave like a Windows editor

If you install the Windows gVim version this will normally be setup in your vimrc configuration file automatically, but it’s always handy to know what settings are making the magic happen.
Vim doesn’t use the typical Windows key binding like CTRL-S to save, CTRL-C,V,X to copy, paste and cut. As a hardcore Windows user you expect these to work for all applications, no matter how geeky they are. If you check out the original vimrc in the Vim installation folder you’ll see the same statements as below.
You can copy these into your own vimrc file.

" Activate all the handy Windows key-bindings we're used to.
source $VIMRUNTIME/mswin.vim

behave mswin

Or you can source the original config in yours:

source $VIM/_vimrc

Now your Vim should (still) behave pretty much like a regular Windows editor, making things a lot easier to use it for all your basic editing.

making it look good

gvim_fugly

Man, it does look ugly doesn’t it? All white and with that terrible font? Now let’s make it look pretty so you don’t have to be ashamed of all those hipsters sporting their fancy Sublime.

This depends on your personal preference of course, but I like it when my editor doesn’t look like it’s from the 80’s. I pasted some of my esthetic config changes below. Each has some comments on it explaining what they do. Use the help feature (:h ) if you want to find out more, and remember to only put things in your vimrc that you understand.

" Display line and column number in bottom ruler.
set ruler

" Display the line numbers.
set number

" Activate syntax highlighting.
syntax enable

" Set a nice theme.
color slate

Check out all the themes you have installed by using CTRL-D (auto-complete) after you typed in :color on the command bar.

if has("gui_running")
  " Set a nicer font.
  set guifont=Consolas:h11:cDEFAULT
  " Hide the toolbar.
  set guioptions-=T
endif

gvim looking pretty

You can exclude hiding the toolbar, but I just find it ugly and never use those buttons anyway. This is very minimal, and there are plenty of other themes and plugins available to change Vim’s appearance, but that’ll be for another post. For more vim customization tips, check out what I have in my _vimrc file.

Hopefully this gets you going in the wonderful world of the Vim editor on Windows. Just keep at it I’d say and feel free to drop any questions or remarks in the comments.

Edit: replaced the KicksassVim Chocolatey package with the Vim one because the first doesn’t seem to be updated any longer.

how to update chocolatey

I use Chocolatey all the time to quickly install software on Windows machines. At some point Chocolatey itself also gets an upgrade, which just happened recently and then I can never remember how to get Chocolatey itself upgraded.

It’s in the documentation somewhere I’m sure, but since Chocolatey is about easily installing and upgrading Windows software, it was bound to work “recursively”.

So here’s how you do that from a Windows shell prompt, for (my) future reference:

    c:\> chocolatey upgrade chocolatey

reset the net

On´n´Off - Going into standby mode

It’s on!

If you want to kick some NSA buttocks and claim your privacy then get yourself this reset the net pack and install some super-duper encryption for your PC, Mac and phone(s).

There ain’t that much on there really, but if you scroll down to the Other Resources section there’s links there like the Prism Break one I mentioned before, which contain tons of (more techy) tools and software for all your stealthy encryption needs.

Photo by Sven Seiler, cc-licensed.

cool geek (dev) stuff I ran into lately

... "Mr. Droopy Eyes!"

I’ve had this list around for a while and though that most people would probably have heard of this by now so I didn’t see the point in posting about it.
Until last weekend someone on twitter was happy to find out about Chocolatey. So I guess not everybody knows these little gems yet, hence this blog post!

  • Chocolatey: a Windows packages manager of sorts. A bit like apt-get on Debian. It allows you to install a bunch of Windows software and tools from the command line. It’s pretty cool and is super handy to get a (developer) box up and running in no time. It’s also handy to keep your installed package up-to-date with the “cup all” statement. Sweet.
    There’s lot’s of good stuff in the gallery already, so you’ll probably find your favorite tool in there. If not, you can add it yourself because it’s built on the NuGet package manager system, or browse what’s available and find some new gems you didn’t know about yet.
  • I haven’t really used Boxstarter myself yet, but if you’re planning on using Chocolatey for some serious VM Windows installer magic, it might come in handy. It builds on top of Chocolatey and allows 100% uninterrupted Windows installs. Thought it was worth mentioning.
  • ScriptCS: one of Glenn Block & co little open source coding adventures. He thought it would be cool to use C# and the .NET framework to run scripts on Windows using the Roslyn compiler API. No need for Visual Studio, project files, compilers or anything like that. Just the scriptcs executable and a text file with your C# script code. Much like Node.js or Python for example. You know, scripting languages.
    Turns out this idea took off like a rocket in the community and has all sorts of cool features by now, like Nuget integration and script packs for reusability. It’s awesome.
  • dotnetfiddle.net : It’s jsfiddle for C# code. It’s a web site where you can type some C# code in a console application, run it and see your output instantly. Great of small bits of test code. It even has intellisense support so it’s easier if to use than LinqPad for this kind of tests apps if you don’t know all the statements by heart.
  • devdocs.io: all web dev docs in one place and easily searchable. Contains docs for thing like the HTML5 spec, JS, HTTP, HTML DOM and the most popular frameworks like Ember, Backbone, Angular, Knockout and Underscore. Also language like Python, Node, Ruby etc. In short, useful stuff for any web developer working with a modern stack.

Image by James Vaughan, cc-licensed.

sync files to your phone with bittorrent sync

Triple Sync

Syncing files with a phone is sometimes a cumbersome and tricky task. I blogged about a few solutions before like this one using FTP, but recently I found another gem.
Bittorrent Sync turns out is awesome to sync large amounts of files over WIFI to and from a mobile device without a lot of effort.

So what is it? Bittorrent Sync is, as you probably guessed, a product from the Bittorrent lads. You can use it to synchronize folders between machines in a distributed, non-centralized way. So you could think of it as Dropbox without having to use the central cloud server. There are
clients for all sorts of operating systems like Windows, Android, Mac and Linux.
The only “downside” here is that you need to have another machine online before the syncing happens as there is no central server that keeps a copy of your files in the cloud. You can also see this as an advantage if you don’t want copies to end up on third-party servers.

So to sync from your main machine to a mobile device, this works perfectly.

Basically you do the following to set up file syncing between your PC and your phone:

  • Install the BTSync application on your PC.
  • Install the BTSync app on your (android) phone.
  • Setup a sync folder on your PC.
  • Scan the QR barcode for this folder from your PC screen with your phone from the app to set up the sync folder on your phone.
  • Sit back and watch the magic happen.

Depending on your settings you can use this to sync in both directions, set up multiple sync-folders, sync with multiple machines etc.

It’s awesome, it’s free and it works like a charm.
I love it.

Addendum: if you upgrade from an older version to v2 of Sync your old sync folders might break. I ended up uninstalling and reinstalling Sync on my PC & phone + recreate the sync folders to have it all work flawlessly again.

Photo by Grant Hutchinson, cc-licensed.

getting good stats without google analytics

I Spy Cynthia K

Google is huge and scary these days isn’t it? I mean they track our ass all over the place and I was actually helping them to do so. On my blog I was using Google’s free Analytics service to keep track of who, when, where and why people came to my blog.

The stats are pretty, easy to understand and extremely extensive. The downside is that all these stats end up in the massive Googleplex data center and are without doubt neatly analysed and lined up with your regular Google searches through that cookie that identifies you no matter if you’re logged on or not.

No me gusta.
So I removed that line of JavaScript from my pages ét voila, no more Google snooping on my watch. Problem is I liked those pretty graphs and lines and I sort of missed taking a peek at them now and then to see what pages where the most interesting and what crazy search results people where using to get to my blog.

Then I ran into something called Piwik. It’s free, open source and it does pretty much exactly the same thing as GA, but stores everything in your own private MySQL DB. It installs as easily as WordPress on your web server, and to activate it you just insert the JavaScript snippet it provides you with. A few seconds later you’ll be getting pretty graphs and figures and spend countless hours spying on your blog’s visitors with the real-time results.

Sweet!

Photo by Flood, cc-licensed.