Saturday, August 2, 2014

How to Change Tab Size in Vim and Other Nifty *Nix Tricks

I learned two nifty *nix tricks this week that I'd like to save here both so I can find them again if I manage to lose my notes (or my muscle memory) and in the hopes that I can save another future dev a little bit of time.

To change your tab size in Vim, first at the command line, type:

vim $HOME/.vimrc

This will open the user preferences file for Vim, creating it if the files doesn't already exist. You will then be popped into your Vim editor, where you can enter your preferences. Remember to type the letter a to enter insert mode. Otherwise, anything you type will be interpreted as a Vim command. Ready?

Here's where you can paste all those nifty "yak-shaving" "time-saving" snippets you've been finding online! I used

set tabstop=4
set shiftwidth=4
set expandtab

Press the esc key to re-enter command mode then :wq to save and exit. Re-open Vim and voila! You've just set your tabs to 4 spaces!


My second trick is much shorter, but it's a great little command just the same. When working in Git, before you add any files using git add type

git diff

to see the changes you've made across all of the files in your working repository. If you've already started tracking the files using git add, type

git diff --cached

It gives you lovely output such as:



That's all for now. Happy coding, everyone!

No comments:

Post a Comment

Comments? Questions? Complaints? Coladas?