Categories
Tools Vim

From VS to Vim

Given my background as a Windows developer, it’s no surprise most of my editing needs were met by the venerable Visual Studio. While at times a bit large and overloaded, VS was a familiar space. With Resharper and a judicious collection of keyboard shortcuts, I was quite happy with my world.

Of course, that all had to change.

Why Vim?
Since taking some grad classes, I’ve picked up vim when not on Windows. It never made the leap to day-to-day use, though. Notepad++ filled the gap when I didn’t need VS, but moving to New Relic and a Mac finally pushed me to vim full time.

There are other contenders–Emacs in the text editor world, and Sublime Text 2 if you’re looking for something more GUI-centric. Sublime falls down, though, since I really want to be able to work across ssh easily. With Emacs I figured I already have one new operating system, why take on another 🙂

Here are some of my favorite tweaks and tidbits regarding vim so far. I’ve posted my .vimrc at https://github.com/jasonrclark/dotfiles/blob/master/home/.vimrc for posterity and sharing. Much of this was learned from the screencasts at https://www.destroyallsoftware.com/screencasts and http://vimcasts.org.

Know the Basics
I claim no mastery, but I’m constantly pleased with the little features that I’m finding built into vim. Examples I’ve found in the last month of work:

  • When using :e to open a file, tab completion works perfectly
  • When using :b to change buffers, typing part of a filename will cycle through matches of that exact string anywhere in the path
  • << and >> will do indentation for you, per your current settings, without leaving normal mode. This works great with the multi-line visual block selections.

Anyone who’s been using vim a while probably wouldn’t think twice about these, but when you’re starting out they aren’t immediately obvious. Read up, watch screencasts, play around. There’s a lot of buried treasure there.

Love your Leader
To effectively edit, whatever the system, you need to learn the shortcuts. And when a critical shortcut isn’t available out of the box, you should define it. Wire those key presses into your muscles until you can do it in your sleep… or more to the point, while your brain is occupied with other things, like the problem at hand.

In vim, many shortcuts work off the so-called “leader” key. Following Bernhardt’s advice, I’ve remapped my leader to “,” which is super-accessible–lots easier than the default “”.

Most of my personal shortcuts follow with the leader key, from “,+r” to run tests on the current file, “,,” to go back to the last file.


Command-T
I’ve tried to minimize the number of full-on vim plugins I use. I figure being able to do most of your work on an un/lightly optimized version of the software isn’t a bad thing.

But Command-T is indispensible. Coming from Resharper, with it’s CamelCase type/file search, for the first few days file navigation was a struggle, especially unfamiliar with the code base as I was. Then I saw this screencast on Command-T, and everything changed. (Sorry for the paywalled link, but Destroy All Software is totally worth it).

While Command-T doesn’t have type-level information, with sanely named class -> file mappings things act pretty similarly. I love typing any parts of the filename and having the list winnow down to all potential matches of that sequence.

While it has it’s quirks, I couldn’t live without Command-T anymore. I set my current directory just above my whole code-base so I can easily slip between files in any of the main projects.

Running Tests
This one’s pretty simple, but this command lets me quickly run unit tests for the current file that I’m on. While I’ve seen more complex setups for this–mostly around remembering the last file run–this works pretty well for now:

map <leader>r :w|:!~/.rbenv/versions/1.9.3/bin/ruby %<cr>

CTags
CTags fill some gaps in type information. Getting those generated properly is a topic for another time, though.

Once you have your tags files, you can easily integrate them into vim like this:



:set tags=ruby_agent/tags,multiverse/tags,rpm_test_app/tags


While I keep my current directory above all my code for Command-T access, I actually only want CTags from part of my tree. This line sets includes just the apps I want.

I also remapped some of the previous/next tag keys to <leader>+[ and <leader>+]. While I try to abide by the built-ins, these keys were just too badly spaced for me to live with.

Conclusion
Plenty of other things I’m learning day to day, but that’ll do for now. I’ve missed the full IDE experience less than I expected, though. Although refactoring and navigation aren’t identical, there’s been less struggle to fill the gaps–and more options opened by the deep customization possible–working with a basic text editor.

Categories
ReSharper Tools

Tools: ReSharper

I’ve long been skeptical of Visual Studio add-ins. This goes back to the VS6 days when I fell in love with an add-in, but eventually removed it because it did such horrific things to my machine’s performance. I felt so betrayed, bereft and I’m sure some other suitable words that start with “b.”
Well, times change. WebMD’s been buzzing about ReSharper. It’s been quite a while since I took the plunge, but I’m never looking back.
Enumerating ReSharper features could keep someone blogging for months at the least, but I thought I’d call out a few of my favorites. Seems like half the time someone talks about ReSharper, I find some widget or keystroke I hadn’t noticed before. Maybe you’ll notice something new.
Go to Definition isn’t busted anymore
This one’s kind of a no-brainer, but sometime around VS 2005, I started finding that “Go to Definition” wasn’t working like it used to. It’d bring up strange files with “[from metadata]” in the title, and only give function signatures.
Turns out, as best we can tell, this is because VS doesn’t properly handle the pdb’s on our assembly references. For various reasons we don’t use project references, so for a long time I suffered without my beloved F12.
Well, ReSharper restores this functionality, and it actually works. Now if I could just persuade it to go to code files for projects I don’t have in the solution…
Run unit tests in-context
Prior to ReSharper, I used TestDriven.Net to run my NUnit tests directly from Visual Studio. I can’t tell you how much of a game-changer that was for my unit testing. Good habits often come from reducing the friction of doing the right thing, and having a single keystroke run tests was a massive step forward.
ReSharper provides the same abilities as TestDriven.Net and more. The only caveat is that sometimes it has trouble running large sets of heavy-weight tests (which we have quite a few of around here). For those, I’ll still crack open NUnit itself so I don’t take my IDE down on a long test run.
But for the small tests that drive my design? “Ctrl+R, O” baby, all the way.
Refactoring
I’ve got a confession to make–as big a fan of refactoring as I am, I never quite got up on Visual Studio’s refactoring support. I didn’t have enough time between using VS 2005 and when I started using ReSharper, so I really don’t know what ReSharper’s got that VS doesn’t.
But if you haven’t had the change to work with a refactoring IDE tool, get one, whatever it is. Just the basic rename is worth the price of entry. Again, it’s all about friction, and the refactoring tool makes it easy to revise names when I find later on (sometimes just minutes) that it isn’t quite right.
Move and renamespace are now dear friends of mine. While good naming is important, it doesn’t help if your namespaces are crap, or worse if they don’t align with where to find the code. Not that many years ago this was a difficult problem for us, but now there’s no excuse.
Find Dependent Code
A recent find for me is ReSharper’s brilliant “Find Dependent Code”. This works at a variety of different levels, from individual files, folders and class names, to referenced dlls.
That last one was a huge time-saver as I’ve been winnowing out dependencies from one of our projects before we start some major work on it. Previously, I’ve relied on the grep + break the local compile method to find where a particular assembly was used within a project. No longer. Now all that beautiful information is just a mouse-click away, with line-numbers and double-click-goto support right there.
What else can I say, I loves me some ReSharper!
Categories
Tools

Tools: Notepad++

Dealing with text is a huge part of a programmer’s job. While issues of proper design, working with the product requirements, and appropriately testing your code might be more difficult to master, simply navigating massive amounts of code day to day can be a challenge in itself.
Hence, text editors have sparked a million flame wars across the internet. My needs are more modest than the sort of flexibility in emacs or more costly proprietary editors like SlickEdit. I primarily use it for editing snippets of text, cleaning up lists, tracking check-in notes before pasting them into our bug tracking software.
My absolute needs:
  • Fast startup (as close to Notepad as possible)
  • Keystroke macros (learned in Brief on my Dad’s knee and still use those skills today)
  • Regex find/replace
Most of the rest is gravy.
Now why, you might ask, wouldn’t I just use Visual Studio? I’m constantly running it for my main code editing. Well, it clearly fails the first test. Especially when hitting “special” files such as XML and HTML, it bogs down loading up specialized editors I just don’t need. It does have a keystroke macro mode, but it also takes an absurd amount of time to start first time around. That just bugs me. Yeah, I use it, but never happily.
So what is the current winner for my random text editor/formatting/processing? The venerable Notepad++. As the name suggests, it’s a better replacement for Notepad, and it scores on all the points I listed above. Even better, the macro record has the same shortcut key as the same laggy feature in VS. Such symmetry makes my nerdy heart go pitter-patter.
Notepad++ has some other nice features too–some keystroke customization, syntax highlighting, viewing options. My only beefs are no multi-window support (it’s single instance) and the Open File dialog hitting the last opened directory rather than the directory of the current file (a minor detail I just love about VS, and wish was done everywhere).
I’ve also toyed with Notepad2, which was almost equivalent for my needs except the lack of keystroke macros. In any case, if you’re using Notepad still for minor text edits, stop it and give something a little better a try.
Categories
Tools

Tools: CLCL

Copy-paste–savior of word processors, “advanced” feature of the masses, bane of software design. Ctrl+C/V is so burned into my fingers that it’s physically painful for me to watch someone clicking the toolbar or menu to copy a piece of text.
But real estate on the clipboard is scarce. Yes, certain applications like Office and Visual Studio provide you with a clipboard ring to save multiple things, but I’ve always found them clunky. Plus, my main use for copying is often bringing stuff from another app, so anything restricted to say, just Word is useless to me.
I’d read about apps that extend your clipboard, but didn’t really pay them much heed until one fateful day. I was writing a new chapter for my book in a web app (which shall remain nameless), and hitting problems. Whenever I’d submit, it was choking. I could click back, and the browser thankfully still had my text. Thinking, “I don’t want to lose what I’ve written,” I copied it into the clipboard. Then I set about trying to fix the app. I shut down the browser (no back anymore), and my speedy little fingers happened to copy another snippet of text–probably a URL or login name, I don’t remember. I’ve blocked it out.
Crap!
Several pages of original text floating in the ether of the clipboard were obliterated. Maybe those clipboard extenders were worth a look.
I’ve settled on CLCL, largely for its simplicity. There’s hardly anything to it, but it will save at least 30 items, crosses reboots, and provides a nice little “save to template” feature where I keep some common strings (login name + domain for instance, since I’m lazy and get tired of typing it into fifteen different apps on our network). Shortcut keys to bring up the saved items completes the picture.
Now I install CLCL anywhere I work frequently. I can’t imagine coding without it there in the background, lovingly gathering up whatever I saw fit to copy, holding it in reserve just in case I need it for later. Thank you CLCL, you’re a lifesaver!