# Visualizing Differences Between Source Modifications in Vim

There’s always something new to learn from #vim, and here’s another gem that allows you to use vim’s built-in diff capability to visually inspect the code changes on your source inline. Add the following into your .vimrc:

function() DiffPreview()
diffthis | vsplit | enew | set buftype=nofile | read # | 1delete | diffthis
endfunction
map <F9> :call DiffPreview()<CR>


In this case, I’ve mapped it to the <F9> function key. How to use this: once you made all the changes you wanted, DON’T save the current buffer yet, and invoke the DiffPreview() function. It’ll provide you with a highlighted 'diff' of all the changes you’ve made. Have fun!