• Format JSON in Vim

    Occasionally I find myself needing to format a JSON document. There a couple tools online that can do it but it’s nicer do be able to do it right inside of Vim without having to leave. Here’s a simple command to do this (you’ll need Python installed).

    Just execute the following with the JSON document open.

    %!python -m json.tool

    Now if you’re like me you won’t remember this in an hour so you can add it to your .vimrc file as a custom command like so:

    command! FormatJSON %!python -m json.tool

    And there you go. Easy formatting of JSON documents.

  • Managing Terminal Jobs

    My terminal workflow usually involves multiple windows and tabs with a job running in each. Lately though I’ve been trying to use the capabilities that Bash provides to manage jobs and run them in the background.

    Here are some useful commands I’ve found.

    Command What It Does
    ctrl-z Suspend the current job
    jobs List the current jobs
    fg %[number] Resume a job in the foreground
    bg %[number] Resume a job in the background
    kill %[number] Stops a job
    %[name|number] Resume a job in the foreground
    disown %[number] Keep a job to running after terminal is closed
    nohup job & Run a job in the background

  • How to Use Git with SVN

    I’ve been using Git for the last couple years and really love it. SVN doesn’t hold a candle to Git in my opinion. Unfortunately though, not everyone uses Git.

    Thankfully, Git provides the git-svn bridge so you can use Git with an SVN repo. It’s a bit different than your typical Git usage but not difficult.

    To start off, you’ll want to clone the SVN repo to your computer.

    git svn clone -s http://path/to/svn/repo

    Notice the -s flag. If you have have the standard SVN layout of trunk, tags, and branches this will make Git aware of that. Otherwise, if you clone without the -s flag you’ll find all of trunk, tags, and branches folders checked out to your filesystem.

    After this you can work, branch, commit as you typically would if you were just using Git. When you are ready to pull down the latest changes from SVN simply do the following:

    git svn fetch
    git svn rebase

    The only thing left to do is push your changes to SVN. To do this you use the dcommit command.

    git svn dcommit

    That’s it. dcommit will push up all your changes. There’s more that you can do with the git-svn bridge but this is just the simple workflow that I use. Check out the docs for more information.