Code merging with VIM

So today I had the chance to learn about vimdiff, VIM’s mode for file comparison and merging. It was a lot better than I expected!

When I switched to using Ubuntu for my day-to-day local testing (because I need reliable Xdebug, and Windows Vista’s Apache-PHP module just wasn’t cutting it as far as Xdebug stability goes), I was worried I wouldn’t have a good merging tool to go along with it. VIM’s been working great as an IDE (just when I was about to go back to my slower XP image, too!), but I was wondering about this vimdiff thing I’d heard about. I figured today that, since a couple conflicts came up in my Bazaar merge, I’d give vimdiff a whirl.

I ran it like this:

vimdiff file1 file2

and VIM appeared, nicely split into two panes and with all the changes highlighted – just like WinMerge! This was cool so far.

Then I had to figure out how to actually, you know, merge the changes. So I typed :help vimdiff and got the help file.

I scrolled through, and picked up the only 3-4 commands I will probably ever need. And here they are for you. Note that these assume you’re just diffing two files…which is all I’ve ever done, so you probably are…and if not, you’re probably smarter than me anyway. And they’re all used in VIM’s normal mode (the one it starts in, unless you’re a Creamer) unless otherwise mentioned.

VIMDIFF COMMAND #1 – JUMP TO NEXT CHANGE

]c – Jump to the next difference. Equivalent to alt + down in WinMerge.

VIMDIFF COMMAND #2 – JUMP TO PREVIOUS CHANGE

[c – Jump to the previous difference. Equivalent to alt + up in WinMerge.

VIMDIFF COMMAND #3 – MERGE LEFT

do – Copy the current difference’s text from the file on the right to the file on the left. Equivalent to alt + left in WinMerge. (The VIM help said it’s do and not dg because dg is too close to dgg – a smart move on their part, as I enjoy not deleting to the beginning of my buffer. But if you ever wanna do that, hey, now you know how.)

VIMDIFF COMMAND #4 – MERGE RIGHT

dp – Copy the current difference’s text from the file on the left to the file on the right. Equivalent to alt + right in WinMerge.

BONUS VIMDIFF COMMAND – UPDATE THE DIFF DISPLAY

Occasionally, as you’re happily merging away, your vimdiff display may get out of whack for some reason. VIM does a pretty good job of preventing it (hasn’t happened to me yet), but if you want to make sure you’re all good, just type :diffupdate. Then continue merging. (If you’ve been reading the WinMerge shortcut mapping, this one’s equivalent to good ol’ F5.)

Bazaar’s bizarre merge markers finally kinda made sense after merging with vimdiff!

Thanks VIM people. Maybe I will be donating to Uganda soon 🙂

I hope this article was useful. If you’ve got any extra tips, post them in the comments!

And hey, if you’re merging on Windows, WinMerge stands as an awesome tool: http://winmerge.org.

Talk to you soon, and happy merging.

Coding on phone; Vim pays off

Learning more Vim paid off the other day. I edited a couple files on a remote server using my T-Mobile G1 along with the ConnectBot program. The process was, of course, pretty simple.

  1. Start ConnectBot on the G1.
  2. Connect to the server.
  3. cd to the directory containing the file I wanted to edit.
  4. Type vim <name of file>
  5. Edit as usual (remembering that ESC is two trackball presses…that one got me at first)
  6. Save file
  7. Check results on Browser, if desired
  8. Rejoice

Pretty easy! Using an editor with windows, tabs, and syntax coloring on a phone gives you a warm, fuzzy feeling.

Happy Vimming,
Kevin

And then there was VIM – a story of Linux PHP IDE frustration

Yesterday, I hit a crossroads in the life of a Web developer. You see, I’ve been doing my testing on an Ubuntu VM lately. It’s been great because Apache runs PHP faster than it did on my XP VM. (If you ever need a break, fire up XP and load the Drupal modules page on a decently-sized site. You’ll have plenty of break time.)

But I had a dilemma; the IDEs just weren’t as good for PHP as my favorite Windows one (phpDesigner). I wanted to think they were. They had features that indicated that they should have been. But, in terms of actual productivity, they just weren’t – either they were too big, or they lacked good code completion at the right time. I was seriously considering sucking it up and heading back on over to Windows. After all, I figured, at least my databases are still on Linux, right? Maybe it’ll be faster. However, I had to pull my local Bazaar branches off of the Linux VM in preparation for the push to Windows, since there were still some changes (I think) that I might not have wanted to commit to the shared repositories yet.  While I was waiting, I figured I’d make a last-ditch effort to find a suitable IDE/editor my projects. After all, my needs in the end weren’t great – give me a couple nice features like code completion, syntax highlighting, and I’m fine.

So I thought I would try to finally learn VIM. I thought it was just a dinky little editor that wouldn’t be practical to use as my development environment for PHP.

I think I might have made a little miscalculation there. I don’t know where I was, but nobody ever told me VIM had so many great plugins or was so flexible! I can set it up practically however I like. It’s FAST. I can avoid using the mouse. I can get my syntax highlighting, code completion, and so on (a link to VIM for PHP programmers is obligatory here). More than I thought, in fact. And then…I can take it with me. Haven’t tried it yet, but VIM is cross-platform, so, in theory, I should be able to take the contents of my .vim directory with me. And I’m a big fan of DRY (something I do EVERY time I install an IDE for the first time on a computer/VM…).

Right now I’m just alternating between vim and gvim. I might wind up trying Pida or another similar IDE that embeds VIM as its editor.

I really ought to learn how to manipulate windows in VIM properly, though. One day!

I wonder if it’s the destiny of all programmers to eventually use VIM or Emacs? They do call them programmer’s editors…

That’s all for now,
Kevin

Portfolio page IS coming

Hi again,

Today I snuck up a link to a portfolio page. Said portfolio will be getting filled in soon. I just wanted to make sure you realize you can just contact me for the moment if you want to know what work I’ve done. Rest assured that I’ve done this stuff before…a lot 🙂

Hope everyone had a great Labor Day weekend.

Our contact form

Update: I’ve finally reached a mutually beneficial agreement with my contact form. It works now.

I just noticed the contact form has become a captcha nazi. Contact forms don’t like me, for some reason. But not to fear – I’m on the case and it’ll be fixed shortly. Watch for one of those fancy Update: messages on this blog post!

Joomla!

I’ve been playing around with Joomla! lately, and it seems to have its pros and cons. Compared to Drupal, it seems a little unnecessarily complex at times, and I don’t really understand the naming conventions for its extensions (“modules,” at least – blocks, the Drupal equivalent, is a much clearer term).

The administration interface is worth applause, though…Drupal’s is simpler, although it can be souped up with modules. It seems like Joomla! has more out-of-the-box but that Drupal is easier to get going with and to tailor to one’s needs. I prefer the latter, since it gives more flexibility to the creation and presentation of content.

Drupal’s also got much nicer URLs, and turning on its “Clean URLs” is super-easy.

So I’m still on the Drupal side, but if you think I should reconsider or try to get more into Joomla!, let me know in the comments.

At some point, I’ll do a proper comparison between the two.

A brand new site!

After some downtime, I’ve finally launched my new WordPress-based site! While it’s rather plain right now, this site will transform over time into a sample of what I can do using WordPress.

For now, browse around, and keep an eye on the blog for more info.