Vim Tips to Make Yourself Faster

I use Vim because it’s faster for me than other text editors. Sure, you could use vim-mode for Atom or one of the various packages for Sublime, but they all have shortcomings — and Vim works everywhere. Here are five things I do to make Vim faster for me.

Relative Line Numbers

Most people know that you can use numbers with Vim commands to make a change multiple times, across multiple lines, or multiple characters. That’s not super useful if you have to stop to count the number of lines in a block of code before deleting it, for example. I use relative line numbers in Vim. The current line is always 0. I can instantly see that a block of code is 14 lines long and d14d to delete it.

https://gist.github.com/joshbetz/271f612479de27f6d958

Relative line numbers in Vim

Use . to repeat the last command

This one is pretty self explanatory. Any command can be repeated with .. If you delete a line with dd and realize that you also want to delete a few more lines, pressing . three times will delete the next three lines. It may seem like a small thing, but that’s half as many keystrokes.

Use = to format code

Often, when you copy and paste code from somewhere else, it won’t be formatted properly. The = command can help here. You can either do something like gg=G to format the entire document or highlight the block of code that needs to be formatted (in visual mode) and press = to format just that block.

Make shifts keep selection

When you highlight a block of code for the purpose of indenting it, the selection is lost when you do the first shift. Often times, you need to shift it more than one position though. The following snippet keeps the current selection in visual mode after you perform a shift.

https://gist.github.com/joshbetz/7f9fca420fae26d04794

Search to find what you’re looking for

I think one of the reasons I’m slower in other text editors is that I use the mouse to browse for specific code instead of using the search function. Start searching with /. After you enter the search and press return, you can jump the next and previous matches with n and N respectively.

5 Tips for Traveling Abroad

I’m spending this week in Lisbon — and it’s my first trip ever abroad. I’m writing this partly for you, but mostly for me, to remind myself for the next time I travel.

  1. Bring an adaptor. The ABCs of being an Automattician is Always Be Charging, and this includes when traveling abroad.

  2. Bring a debit card to withdraw cash for the best foreign exchange rates. As much as we all love Apple pay, credit cards aren’t as ubiquitous abroad.

  3. Check the weather before you leave, so that you can appropriately pack rain jackets or WordPress sunglasses (don’t forget the sunscreen).

  4. Get prepped for figuring out data abroad. This could mean getting Skype credits to use Boingo hotspot on the go, or getting international data set up on your phone ahead of time.

  5. Passport. Get one, and don’t leave it behind.

One Year at Automattic

It’s been a year plus one day since I graduated from the University of Wisconsin, which means I’ve been working at Automattic for exactly a year.

https://twitter.com/jshbz/status/352467440040542208

In the past year, I’ve seen whales in Boston, palm trees in Santa Cruz, dolphins in Key West, and a sun rise in Napa.

http://instagram.com/p/a_SNKsjrLz/

http://instagram.com/p/e4-6HijrOC/

http://instagram.com/p/lBF0aDDrKS/

http://instagram.com/p/mVHA-WjrE-/

I’ve also had the chance to work with the best people, coolest clients, and interesting projects I could have hoped for in my first year out of school. I interned at Automattic the summer before my final year of school. I wanted to work here for a long time before that, but after meeting the people I would work with, I didn’t want to work anywhere else. I’m proud of the work we do, contributing to the WordPress community, our open source code, but it’s the people that really make it a great company.

I’ve been able to do all of this without moving away from my friends, family, and the best place in the world that’s buried by snow for 5 months every year.

http://instagram.com/p/ZS-kGDDrDS/

http://instagram.com/p/hWgYkJDrM9/

http://instagram.com/p/htXMvRDrNm/

This weekend at the 2014 UW graduation, I was reminded how I felt a year ago — proud of what I had accomplished and where I was going. We get better at what we do every day and I’m just as proud to work here today as I was then.

Also, we’re hiring. 🙂

#postyourprompt

 Let’s have a little fun on a Friday. What’s the command prompt on your local machine?

via Ryan

I use Zsh, so I also have a right prompt. Most of this is pretty obvious, but I’ll explain some of the cooler things that might not be.

  • dashboard is the current branch I’m on in a git repository
  • fda1011 are the first 7 characters of the hash of the current commit
  • The X means there are uncommitted changes
  • The arrow is green when the return code of the last command was 0 and red otherwise
  • cd automatically calls ls as well

It’s all available on Github.

Git essentials for SVN users

Coming from Subversion, the extra steps involved in working with a Git repository can be confusing. Here are some basic concepts and commands to get started with Git.

I find that actually doing something is the best way for me to understand. If you’re the same way, the Github tutorial by Code School is great.

Concepts

There are a couple conceptual differences between Git and Subversion that it helps to understand before getting started.

Centralized vs Distributed

Subversion is centralized version control — every commit lives on a central server. Git is distributed version control — everybody has a copy of the repository. When you commit to subversion, the push to the central server is implicit. The commit and push are discrete actions in Git. This means you can do work and commit changes without necessarily being connected to the Git server. Another advantage is the ability to make commits locally without necessarily publishing your work.

File vs Change-based version control

Subversion is file-based — when you make changes and run svn commit, it commits all the changed files by default. Git is changed-based — when you make changes, you have to run git add to “stage” changes. You can get similar behavior to Subversion with git commit -a. The “a” flag tells Git to add all changes in tracked files.

Commands

  • init – Create a new repository.
  • clone – Set up a repository that already exists on a remote server.
  • add – Stage changes to be committed.
  • commit – Add changes to the local repository.
  • push – Push unsynced commits to a remote repository.
  • pull – Pull unsycned commits from a remote repository.

Basic Workflow

  1. Get the latest version of the code. If you already have the repository, you can use git pull to get the latest changes. Otherwise, git clone will download the code from a remote repository and set it up locally. If this is a new repository, you can set it up with git init.

  2. Make changes.

  3. Share your changes. git add <file>; git commit; git push or git commit -a; git push.