VIM: Saving with sudo, without opening with sudo

It happens all the time. You open a file in VIM, you make three and a quarter trillion changes, and then realize you needed sudo but didn’t use it when you opened the file. What do you do?

Well, if you might save the file under a new name, then quit, delete the original and rename the new file with the original name. It works, but its really annoying.

Luckily there is a cool trick in VIM that lets you save with sudo, even after having opened a file without it. Here it is.

:w !sudo tee %

Hit enter after typing that in, you will be prompted for a password if necessary, and then you will then get the following message.

Press ENTER or type command to continue

Go ahead and hit enter, and assuming you actually made some changes, you will then get the following message.

Press ENTER or type command to continue
W12: Warning: File "sites-available/webgrind.conf" has changed and the buffer was changed in Vim as well
See ":help W12" for more info.
[O]K, (L)oad File:

This is just telling you there are two versions of the file, the old one and the new one and gives you an option to simply acknowledge, or to load the new version. You are typically going to want to enter “L”.

Thats it, your file should be saved now. Cool trick, saved me some frustration many time.

Note: I first heard of this trick at WordCamp, but I can’t remember who it was that mentioned it.


Sears Community & Kmart Community Launched

For the last few months I’ve been neglecting this blog and my publicly available plugins. Thats because 200% of my time has been tied of in this very large projects – the mySears Community and myKmart Community for Sears Holdings Corporation. This matching pair of Q&A style customer service sites have been migrated from a third-party host known as Viewpoints, and onto a self-hosted WordPress Multi-Site installation.

Today I’m happy to say that we’ve launched both.

While I’ve taken part in countless migrations to WordPress from other systems, including one from Viewpoints – this project was truely like no other – not only in the number of hours worked, but also in its technical challenges. Due to fuzzy requirements at the start of the project, the end product turned out different from what we expected on day 1 of development. If I were able to solution this project over again knowing what I know now, I would have chosen a much simpler approach. However it resulted in the development of some very interesting tools.

Of the parts I got to work on, there are 3 plugins that I’m proud of and that I think will be useful to the WordPress community – Custom Comment Type, Section Fronts, and WidgetPress. I won’t go into too much detail in this post, but heres a brief description of those three.

  • Custom Comment Type – create Custom Commeny Types much the same way developers already create Custom Post Types.
  • Section Fronts – A custom post type called ‘section’ that can be chosen to represent a category, post type archive, or even an intersection between the two. Similar to the way admins can already select a ‘page’ to represent the front page.
  • WidgetPress – A layout management tool based on the existing Widgets API infrastructure. Overhauled to work off two custom post types and a custom taxonomy – sidebars (referred to as dropzones) can be sized and created on the fly on a page-by-page basis leveraging a css grid framework on the front end. This – especially when used in conjunction with Section Fronts – has by far the greatest potential to make an impact, and opens up a whole host of possibiities for how WordPress is used.

I’ll try to write more about each plugin in the weeks to come. For now, none of them are clean enough for me to release them publicly. I’d like the opportunity to rewrite each one from scratch and do things the right way now that I know how it all needs to work – but I dont think I’ll have that much time so I’ll have to settle for something in the middle.

I’ll also throw up some screenshots for some of these, and at some point I’ll probably create a demo video of WidgetPress in action.


Kmart BirthdayClub Launch

Yesterday we launched a huge update and redesign of the Kmart BirthdayClub website for Sears Holdings. Not only does the new theme look a lot better, the content is much better organized, and its more usable that it previously was – both from an end-user perspective, and from a content management perspective.

Kmart BirthdayClub was originally migrated to WordPress approximately 7 months ago from its previous static and flash-based templates hosted on a WebSphere platform. The site attracted a decent amount of traffic and so some additions were made. The existing theme however was ill-equipped to handle the various new sections of content. The new theme solves most of the usability and information architecture problems that were present in the previous theme, looks a lot better, and leverages jQuery and CSS3 features like gradients, and box shadows to avoid unnecessary flash elements and imagery.

Like other sites I’ve worked on for Sears Holdings – FitStudio Gear, the Kmart Fashion Blog, and the Kmart Fashion Lookbooks – BirthdayClub makes use of my own Category Template Hierarchy plugin to modify WordPress’ native Template Hierarchy, allowing us to create specific templates for child categories. Every time I work with one of my own plugins I learn a little more about how to improve them, and that plugin – along with Media Categories – is due for an update soon.

Development for this project actually concluded a couple of months ago, but the launch date was repeatedly pushed back due to business constraints – much to the chagrin of Jason Corradino, who worked on the social media aspects of this project with me and wrote his own blog post about it long ago. He’s been eagerly waiting to publish it since we finished work  – unlike me, who lazily waited until last night  to write this, only once I realized we were really going to launch this time. 🙂