giant robots smashing into other giant robots

Written by thoughtbot

gabebw

Clone Me Maybe

Let’s say you’re on the Github page for rails/rails. Copying the URL from the  top of the page, pasting it into the terminal takes too dang long! Instead, put this in your ~/.gitconfig:

# ~/.gitconfig
[url "git://github.com/"]
  # Read-only
  insteadOf = gh:

In the terminal:

$ git clone gh:rails/rails

Read/write github repos

What if I want to clone something to which I have push (write) access, like thoughtbot/high_voltage? Here you go:

# ~/.gitconfig
[url "git@github.com:"]
  # With write access
  insteadOf = wgh:
$ git clone wgh:thoughtbot/high_voltage

Easily add a Heroku remote

Now then, what if you need to add a Heroku remote for the sushi app? You could go to Heroku, log in, click “My Apps”, click “Sushi”, and find the remote URL. Or, you can do this:

# ~/.gitconfig
[url "git@heroku.com:"]
  insteadOf = heroku:
$ git remote add heroku:sushi.git

Your turn

Before I learned this tip, I missed it real bad. For more, check out my gitconfig. What are your little Git tips?

codeulate

The vim learning curve is a myth

I’ve been speaking about and teaching people vim for several years now, and I’ve noticed a surprising pattern: people are literally afraid of learning the editor.

Over the years, the popular mythology around vim has become that it’s insanely difficult to learn; a task to be attempted by only those with the thickest of neck-beards. I’ve heard dozens of times from folks who are convinced it will take them months to reach proficiency.

These beliefs are false. Here’s what’s true:

You can learn to use vim in 30 minutes.

Go to your shell and type vimtutor. The tutorial that’s presented is excellent and you’ll be through it in no time. Once you’re done, you’ll have the rudiments needed to get your work done. You won’t be fast yet, no; but you’ll be competent. And even after those 30 minutes, you’re going to start grasping the ideas that make vim so amazing: the brilliant design decision that is modal editing, the composability of commands, the clever mnemonic naming of commands. These will be enough to make you want to learn more.

Learning vim is fun because it’s game-like.

No one ever says “I’d love to learn Street Fighter 2, but there are just so many combos!” People don’t say this because learning a game is enjoyable. You start off with just the basic kicks and punches, and those get you by. Later, you learn more advanced moves, maybe even by accident.

Learning vim is like this. At first, you do everything as simply as possible. Then you start to wonder if there are faster ways to get things done, and there are! If you chain those commands together they just work! You bump into things accidentally, or maybe you spend some time in the extensive help files. Over time, you burn a few advanced tricks into your muscle memory.

Soon, you realize there are many ways to accomplish your edits, and you strive to do them in as few keystrokes as possible. This can be incredibly satisfying, particularly to us technical-types that seem to have a higher-than-average appreciation for efficiency. It may be hard to believe that trimming one keystroke off a command will one day trigger a dopamine response, but I swear it’s true. Just ask these guys.

You’ll be faster than your old editor in two weeks.

If you use vim all day and make an effort to use it well, you’ll be editing code faster than you did in your old editor within two weeks. A couple tips to help you on your way: keep a cheat sheet of commands you’re trying to commit to memory, find a friend that’s an experienced vim user for the many questions that you’ll have in the beginning (ask in #vim if you have no such friend), and pay attention to things you do that feel inefficient (there’s almost definitely a better way). If none of that works, reach out to me on twitter and I’ll try to help you out.

It’s effing worth it

There’s a reason everyone at thoughtbot is using a 20-year-old text editor. There’s a reason I’ve flown to other countries to try to convert more vim users. There’s a reason people love this editor. Maybe you should find out why.

Good luck! And happy vimming.

dancroak

Love, hate, & tmux

Many at thoughtbot run their editor+shell combos inside of tmux. Some remote pair program with ssh, vim, and tmux.

Getting started with tmux, these are the questions I’ve had.

How do I get started?

Install tmux, read the documentation, and fire it up.

brew install tmux
man tmux
tmux -u

Can I make the environment look good?

Yes. We have these lines in tmux.conf in thoughtbot/dotfiles:

# improve colors
set -g default-terminal "screen-256color"

# soften status bar color from harsh green to light gray
set -g status-bg '#666666'
set -g status-fg '#aaaaaa'

# remove administrative debris (session name, hostname, time) in status bar
set -g status-left ''
set -g status-right ''

What’s a prefix?

The “prefix” namespaces tmux commands. By default it is Ctrl+b. In our tmux.conf in thoughtbot/dotfiles, we bound it to Ctrl+a:

# act like GNU screen
unbind C-b
set -g prefix C-a

How can I scroll up to see my backtraces?

This was non-obvious to me.

Enter “copy mode”:

prefix+[

Use vim bindings to page up and down:

Ctrl+b
Ctrl+f

How can I copy text?

Add this to your tmux.conf:

# enable copy-paste http://goo.gl/DN82E
# enable RubyMotion http://goo.gl/WDlCy
set -g default-command "reattach-to-user-namespace -l zsh"

How can I make tmux act more like vim?

Add this to your tmux.conf to use vim’s home-row keys for movement between windows and panes:

# act like vim
setw -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind-key -r C-h select-window -t :-
bind-key -r C-l select-window -t :+

How do I name sessions?

One day I might work on Airbrake. Another day, a client project. I’d like to name my tmux sessions so I can leave one, drop into another, and go back to the original with all my state maintained (files still open in my editor, console/logs I want open, etc.).

Create a new session:

tmux new -s airbrake

Attach to a session:

tmux attach -t airbrake

How do I split and move between windows?

Create a window:

prefix c

Move to window 1:

prefix 1

Move to window 2:

prefix 2

Kill a window:

prefix x

I believe in setting my mouse free but it takes time for muscle memory to make this fast.

How do I reload ~/.tmux.conf?

After editing ~/.tmux.conf, execute this from a shell:

tmux source-file ~/.tmux.conf

Give it a shot

I’ve had a love-hate relationship with tmux in my first week using it, but the brief moments of flow I’ve experienced so far are enough to keep trying it.

Give tmux a shot and if you have any other tips, I’d love to hear them.

Written by .