Make Sublime Text 2 More like Vim: Wrap Code, Go To Last Edit, and More

I’ve been trying out Sublime Text 2 as a replacement for Vim. While I enjoy using it and I experienced the “Wow, this does 90% of what Vim does” moment, I kept a running list of all the features in the remaining 10% that I relied on every day.

These included:

  • Better code wrapping (gq)
  • Go to last edit ('')
  • Go to file in Ack search output
  • Display full path to current file (:echo expand('%:p')<CR>)

However, Sublime Text 2 has a great Python API and I was able to whip up plugins for these tasks that perform just as well as in Vim.

Better code wrapping

Vim’s reformat text command (gq) can take multiple paragraphs and text in comments and flow them to the current textwidth setting. Some people don’t care about this, but I prefer to keep lines of code less than 80 characters wide, so I can open multiple files side-by-side. (Also, Pep-8.)

Sublime Text 2 had a “wrap” feature, but it failed to intelligently wrap comments, it joined separate paragraphs together and it wouldn’t reflow selected text (only the paragraph around the cursor).

The plugin I wrote creates a Wrap Code command (mapped to gq in Vintage mode) that works reasonably on commented lines of code (and uncommented lines), multiple paragraphs and selected text, thanks to the codewrap.py module written by Nir Soffer.

Download the WrapCode plugin on Github.

Go to last edit

I’m used to typing '' in a buffer in Vim to move the cursor to the last edit. Great feature. Totally underrated.

If you use Vintage mode in Sublime Text 2, you’ll quickly discover that this command does nothing — worse than nothing, in fact, as it seems to refocus your cursor somewhere other than the text of the buffer, forcing you to use your mouse to recover.

While I couldn’t bind my plugin to the '' command for some reason, I bound it to Super+' and it works the same way as Vim’s.

Download the GotoLastEdit plugin on Github.

Open search result

Another thing I missed about Vim was its Ack plugin. The “Find in Files” feature of Sublime Text 2 is great, but it didn’t provide an easy way to quickly open a file listed in the search results.

So I wrote a plugin that, in a Search Results window, allows you to do one of the following:

  • On a “matched” line in the search output, open its file at the line of the match
  • On a file path in the search output (without a line number), open the file in a new tab

Download the OpenSearchResult plugin on Github.

Display full path to file in status bar

I use Vim in OS X’s full screen mode, with no tabs or status line. Working this way, I don’t have reference to the path of the current file. Of course, I know the name of the file because I usually typed it, but sometimes the full path is important; e.g., if I have two Mercurial branches of the same code in different directories.

So, I have a command mapped to ,F that displays the full path. Then it silently goes away after a moment. I love that command.

I couldn’t find an ideal way to implement this in Sublime Text 2, other than to create a command that would toggle displaying the path to the current file in the status bar. It works well enough for me, however.

Download the FilenameStatus plugin on Github.

Installing the plugins

You install these plugins the same way as other Sublime Text 2 plugins, by downloading the files and dropping them into the Packages directory.

See this documentation for more details if you need additional help installing plugins.

The default key bindings are intended for Vintage mode and are oriented for OS X.


Sharp Edges: Protecting Ourselves from Digital Publishing

Nicholas Carr wrote in a recent article that he considered the ability of publishers to change text after they had released it “insidious” and a “bane” of digital publishing — specifically, if such changes are made in response to market research. I agree that there is a challenge inherent in the new ease with which


iA Writer and Notational Velocity

The OS X apps iA Writer and Notational Velocity are great for writing and taking notes, respectively. I wanted to try using them together, by setting iA Writer as the external editor for Notational Velocity, but after doing so I noticed that iA Writer would not open with the keyboard shortcut (Command-Shift-E), and it was


How to Fix Slow Scrolling in Vim and MacVim on OS X

I finally discovered the cause of my #1 OS X problem: slow scrolling in Vim, both in Terminal.app and in MacVim. There was always a marked difference between Vim on my Mac and Vim on Linux. Scrolling with the movement keys (j/k in particular) was blindingly fast on Linux, but plodded along on my Mac so


Instant Django Dev Environments with Tmux, Tmuxinator, and Virtualenvwrapper

This post describes how to use a few common tools to instantly set up and tear down Django development environments. I’ve found that such automation is most useful when switching between branches in source control. Without automation, you have to manually kill and reconstruct any Django shell and development server instances for each branch (and


Self-Reliant Veganism

“Trust thyself: every heart vibrates to that iron string.” When I first read “Self-Reliance,” these words sunk into me, but I must have skimmed the rest of the essay. Emerson’s style and vocabulary put me off, an experience which I attributed to 150 years of drift in the English language. The problem only got worse


No More Supermarket Blues

A few weeks ago, Kim and I were riding home from our weekly trip to Fred Meyer, and I had an epiphany: I never wanted to go back. Kim wasn’t fond of Fred Meyer, either, so we hatched a plan to limit how much time we spent at the supermarket, and how much we bought,


Riding the Springwater Corridor

This weekend, Kim and I rode bikes from our apartment in the Lloyd District of Portland to the Tacoma Bridge, following the Esplanade and the Springwater Corridor. The ride took a couple of hours at our mild, Sunday-morning pace, and it offered gorgeous views of the Willamette River and Oaks Bottom Wildlife Refuge. Spring and


Learning Clojure

Clojure is a new functional language for the JVM. This post is a collection of links, articles, screencasts and free books I’ve found to help me learn the language and understand functional program design. Key features Here are some key features of Clojure that I find extremely interesting: Designed for concurrency A Lisp dialect –


This Time It’s War

My favorite board game ever has to be Aliens, published in 1989 by Leading Edge Games. If you’ve never played it, there is a Flash adaptation available, which seems to be free. I was introduced to the game in the early 90s by the same guy who taught me how to play Dungeons & Dragons