Programming

Use vimdiff as git mergetool

Using vimdiff as git mergetool can be pretty confusing. Multiple windows, little explanation. This is a short tutorial to explain basic usage, what do LOCAL, BASE and REMOTE keywords mean. This implies that you have at least very little basic vim knowledge (how to move, save and switch between split windows), if you don’t – there’s a short article for you: Using vim for writing code. Some basic understanding of git and branching is required as well, obviously.

Git config

Prior to doing anything, you need to know how to set vimdiff as a git mergetool. Do:

This will set git as default merge tool, will display a common ancestor while merging and will disable the prompt to open the vimdiff.

Creating merge conflict

Let’s create a test situation. You are free to skip this part or you can work along with the tutorial.

Let’s add some animals:

Save the file.

That’s where we get a merge error:

Resolving merge conflict with vimdiff

Let’s resolve the conflict:

9a89f5ead60e7b010812891732c22c52

This looks terrifying at first, but let me explain what is going on.

From left to right, top to the bottom:

LOCAL — this is file from the current branch
BASE — common ancestor, how file looked before both changes
REMOTE — file you are merging into your branch
MERGED — merge result, this is what gets saved in the repo

Let’s assume that we want to keep the “octodog” change (from REMOTE). For that, move to the MERGED file (Ctrl + w, j), move your cursor to a merge conflict area and do:

Which gets the corresponding change from the REMOTE and puts it in MERGED file. You can also do

Save the file, quit (fast way to write and quit multiple files – :wqa).

Run git commit and you are all set!

Programming

Git pretty log output

This alias has been around the web for quite a while, but it does look fantastic indeed (don’t have a lot of branching in personal repositories, but branching graphs are beautiful).

8b571d1b74275c543f2e8e355e86ff38

To have alias git pretty-log, execute following command:

Programming

Download gists from prompt

Wrote a little script to download gists from command prompt.

Generate your Github API Token under Settings -> Applications, change it within a script, then do:

Where ~/bin is a directory in your path. Now you can use it as shgist file to quickly download your gists (Gist on Github).

Random notes

My most used bash commands

Shell history can tell a lot about it’s owner. What’s in your shell?

Here’s my office cygwin prompt, with comments:

Random notes

Colorless week results

Round-up of The Week Without Colorful Prompt.

I worked with colors disabled in bash, git and vim for a week – so how did it go? It is definitely an interesting experience, but such a harsh change doesn’t really work out with everything.

Bash

Disabling colorful PS1 and removing color output for ls commands forced me to concentrate more on the actual text, changing the perception of general bash workflow. I was more concentrated on the task, missed less details and generally paid more attention to the output.

Git

Never repeat my mistake by disabling colors for git diff… Log and status are fairly easy to read, even though it noticeably slows down the workflow.

Vim

Vim without code highlight forces you to remember your code structure better, which is a great thing – without need to rely on color hints programmer has better understanding of the code he/she is writing.

Now, after experiment is over I mainly returned to using colorful prompt. But I do turn syntax highlight off once in a while – it allows you to see problem from new angle and be more efficient at finding a solution – try it!

Random notes

A week without colorful prompt

I noticed that I rely on colors in bash terminal a lot: git output, diffs, directory and file listings… It gets worse when using vim: I feel lost without cozy syntax highlight guidance.

b8dc86cb91850cb483239c78a33597ac

Time to stop using output colors for a week: shell, git, vim – only plain text, no fancy colors. git config --global ui.color off, no --color flags in shell and syntax off with simple color scheme for vim.

8f83dc7a03d9c363d39003ea2368c552

What can I gain from it? This will definitely reduce my productivity for a few days, however I have a hint of idea that changing visual code representation will give me new insight on what I am currently writing.

Link to related commit on GutHub

Check back in a week to see how did it go!

Programming

Editing bash command in vim

You can open current command you are typing for editing in your default text editor by pressing Ctrl + x + e. It will be executed after you write and quit the file. Perfect for editing long/multi-line commands where typos are likely to occur. Consider something like this:

Editing this in vim is much more satisfying, isn’t it?

You can also open last executed command for editing if you execute fc command. You can also edit last command starting with a certain pattern using fc [pattern] (you can skip the editor and execute output of fc adding -s option, useful tip is to have alias r="fc -s", which would allow you to execute last command starting with “cc” by running r cc).

P.S: In order for this trick to open vim and not any other editor, make sure you have line EDITOR=vim in your ~/.bashrc. Obviously this works with any text editor.

Programming

Vim, pathogen and git submodules

Step by step tutorial to organize your vim config files using git, pathogen and git submodules. This tutorial assumes that you are familiar with git basics, but you don’t really need to understand every step in order to follow it. For simplicity only .vim directory is a repository in this example. You may want to have all your dotfiles under version control and use a script to symlink files to home directory. Example: https://github.com/ruslanosipov/dotfiles

Setting up

Let’s assume your .vim directory is a mess and is not under revision control. Let’s initialize a repository.

Now let’s create .vim/bundle directory and clone pathogen plugin as a submodule.

Pre-pend following code to your ~/.vimrc to load pathogen from non-default directory:

Let’s add some more plugins as git submodules, for example:

Now we can add and commit everything and push it to a repository.

Deploying

Assuming that your repository is located at [email protected]:user/project.git:

And you are done, all plugins are downloaded from their repositories now.

Maintaining

Git submodules keep track of specific commits and are not being automatically updated when target repositories have new commits. In order to update plugins you have:

You probably want to make sure that new versions of plugins are compatible with each other before committing though.

Random notes

IRSSI – ignore all from everyone

If you visit noisy IRC channels like programming ones on freenode, you probably want to ignore all the annoying status messages.

To permanently ignore joins, parts, quits and nickname changes from every channel in IRSSI:

Keep forgetting the exact syntax, maybe clipping the snippet in a blog post will keep it in my memory.

Programming

Vim movement cheatsheet

10debe92319477027aab6a89ee404f1b

I had this lying around for a while now, this is great vim movement commands cheat sheet made by Ted Naleid (link to an original post). It does an amazing job in helping to memorize essential vim movement shortcuts.