Tuesday, April 24, 2012

30 days and 30 nights of Vim

or, how I learned to stop worrying and love the registers

My trial period for ViEmu from http://www.viemu.com/ ran out yesterday. I have been using it in my day and night coding during the last 30 days of work, hoping that having it installed and trying my best not to turn it off, would force me into learning how to use it. I would say that I've pretty much managed to get the most out of my 30 day trial period, being that I've been in crunch the whole time. So I reckon I've managed to easily amass over 300 hours working with the plug-in, or using Vim directly in other contexts. I have gone from really not getting it at all, to installing Vim itself and making it the default program to read, write, and edit text files of all varieties from logs to xml to batch files to source.

So, 30 days later, 30 days from installing the plugin, what are my thoughts? Why did I change from "Visual Studio is just fine as it is" to "Oh my, it feels so clunky" ?

There were downsides, and most of them came from ViEmu being in visual studio. I don't miss +w, c to close windows. That was quite infuriating, and in the case of find-in-files and compilation windows, it just didn't work, just like searching in those windows didn't work either. but it's only a shortcoming of me not knowing how to push past the unbindings of ViEmu and set up a mapping. That much I've learned: the reason you're not productive in vi is never vi's fault, it's that you didn't configure it for your purpose. vi is naturally configured for all purposes at once, and once you get your head around the fact that this "programming" tool, is also a diffing tool, a writing tool, and a reading tool, you begin to see why, even with lots of special key combinations there's only so much you can fit on one keyboard. In short, vi is setup for everyone by default, you need to make it your own.

Post ViEmu, I now find myself opening a file and hitting / to find things, then after realising that's not available, I go back to +i, and then when I find the first occurrence, I find myself replacing it with n. Okay, so I get it, the muscle memory has already soaked in for the basic stuff. I now find Visual Studio slow to manoeuvre around. Finding forwards, backwards, moving my counts of words, all those things I'm missing already, but the main thing when it comes to editing existing code is operations on text. The most basic one I miss is the one mentioned by the developer of ViEmu: duplicating a line ready to make changes.


What else I am missing already is how fast the macros were. Visual studio macros used to be fast, then they seem to have stuck in an entire visual basic backend the size of a small house and creating a quick macro takes ages, but not quite as long as it seems to take to play it back. I'm not sure how they took a system that worked and broke it so hard, but I've not seen any point in using visual studio macros since C++6.0. They're just too slow. Anyway, in vi macros are amazing. They can be created and reused incredibly fast, and they can be edited too without requiring switching out to a vb editor. In fact, they can be edited in the file you're working on. For those of you not in the know, I'd suggest that macros and registers are actually the main feature you want to get your head around. Once you have tried and fallen for this mind-blowingly simple system that has so many emergent properties, you'll never want to go back. For myself, it was at least two weeks into my learning before it was pointed out to me that macros and registers were the same thing. That was a long time to wait for learning about such an amazing feature.


But I'm sure there are more things that are amazing. I learned that I need to know about ctags, but still haven't. I have learned that I should learn how to read the help, but I haven't. I know that I need to start compiling my own .vimrc, and I still haven't properly other than some basics like the font and my preferred windowsize.

Take the time to do it. Learn vi, not learn how to open a file and press i, but actually learn vi. You won't regret it unless you give up. It took me, a long in the tooth modeless editor fan, two weeks to get good enough with it to say it was bearable, and four to say I can't live without it.

It's on very machine I work with now and it's not coming off.


wererogue said...

How was ViEmu compared to just switching out to Vim?

fabs(); said...

I couldn't trust myself to stick with it that way, and I couldn't navigate the millions of lines of code without visual assist, so I would have only touched on Vim briefly.

I would say, ViEmu gives you more power in VS, but feels awkward compared to pure Vim.

Once I get ctags in my head, I'm sure I will be able to edit the whole codebase better than I ever did with VS.

bullno1 said...

Have you tried VsVim?
It works pretty well for me. It even reads your vim config files.

fabs(); said...

I will try that out as soon as we're allowed to move to 2010. Stuck on 2008 until we have completely finished the game.