My Current Vim Configuration

This is my current .vimrc file at work.

"Block Cursor
let &t_ti.="e[1 q"
let &t_SI.="e[5 q"
let &t_EI.="e[1 q"
let &t_te.="e[0 q"

"Syntax highlighting
syntax on
filetype on
au BufNewFile,BufRead *.jq set filetype=javascript "jquery files
au BufNewFile,BufRead *.html set filetype=javascript
au BufNewFile,BufRead *.htm set filetype=javascript

set cindent

"Text Display
set number
set bg=dark

"Search Settings
set hlsearch
set incsearch
set smartcase

"Mistype correction
command W w
command Wq wq

"Window Split Settings
set splitbelow
set splitright
set wmh=0 "Free up screen real estate from minimized windows

"Easier Split Navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

"Allow erasing with backspace in insert mode
set backspace=2

Better Vim Splits

I thought I knew everything there was to know about vim splits. Generally I’m the guy with so many different windows open that you can only see three lines at a time. But once again, I have learned a cool tweak for using vim. I won’t spoil all the details, so check out :

The code snippets (for your ~/.vimrc) are below:

Easier Split Mappings: (Ctrl-j instead of Ctrl-w j)

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

More Natural Split Opening:
This makes new splits open to the right or bottom of the window

set splitbelow
set splitright



The most useful thing in Bash

So I was reading hacker news when I stumbled across this gem:

Pretty cool right? I’m going to keep a copy here so I can find it in the future. Much thanks to Jude Robinson for posting this up!

Create ~/.inputrc and fill it with this:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

This allows you to search through your history using the up and down arrows … i.e. type “cd /” and press the up arrow and you’ll search through everything in your history that starts with “cd /”.

Taking the MD5 Hash of a directory’s entire contents

So my harddrive recently failed. Fortunately I had backups, which means I’ve been copying a lot of important files over to my new harddrive. Once concern that I’d always had was dealing with file corruption. I’d been meaning to get around creating a md5 database of my pictures and music files. Well I’ve taken the first step.

But how I can I easily tell if something important has changed? Some quick googling found this StackOverflow Post. Works great on GNU/Linux, unfortunately I’m using a Mac, which is BSD based system. So let’s fix it up!

Here’s my version, Uncomment out the proper line for your operating system.



if [ $# != 1 ]; then
        echo "Calculates MD5 Hash of entire directory contents"
        echo "usage: md5dir "
        exit 1

#Non-bsd (GNU linux) systems
#find $1 -type f -name *.py -exec md5sum {} + | awk '{print $1}' | sort | md5sum | awk '{print $1}'

#For BSD based systems
find "$1" -type f  -exec md5 -q {} +  | sort | md5 -q

After I wrote that, I wrote this little script to quickly compare the md5 hashes of two directories. You could always use a recursive diff, but I wanted to compare hashes. It uses the md5dir script I wrote above, and assumes that you have placed it somewhere in your path. (Put md5dir in /usr/local/bin)



if [ $# != 2 ]; then
        echo "Compares MD5 hash of two directories"
        echo "usage: comparedir  "
        exit 1

echo "Comparing $1 to $2"
x=$(md5dir "$1")
y=$(md5dir "$2")

if [ $x == $y ];
                echo "Directories Are Matching!"
                echo "Directories DO NOT MATCH!"

echo "$1: $x"
echo "$2: $y"