Skip to content

Derek Wyatt's Blog

Vim, OO Design and Piles of Uselessness

Archive

Archive for August 20th, 2009

Ever been inside a code block and want to reformat (via ==) a number of lines but not the whole file and not line by line?

Let’s say you’ve got code like this:

class MyClass
{
public:
    MyClass()
    {
std::cout << "In MyClass constructor" << std::endl;
}

    int somefunc()
    {
for (;;)
    {
std::cout << "breaking" << std::endl;
    }
    }
};

That’s just not ideally formatted, is it? Here’s one cool way to format it:

  • Put the cursor somewhere inside the outer most block – say on public: or on the blank line between the constructor and the function.
  • hit: =aB

That will format “a block” and that means it formats the outer block recursively down to the inner most blocks. Not that this is a great demonstration, but it looks like this:

class MyClass
{
  public:
    MyClass()
    {
        std::cout << "In MyClass constructor" << std::endl;
    }

    int somefunc()
    {
        for (;;)
        {
            std::cout << "breaking" << std::endl;
        }
    }
};

David Fishburn (of vim_use Mailing List and other fame), suggested that I put up some videos regarding the vimrc file, and I thought that this was a great idea, so I started this morning – not with the videos though :) I want to get a decent idea of what I want to talk about before diving into that medium, so I started with a bit of work on this site with some pages on the vimrc. So far all I’ve got is the bare minimum, but I’ll be fleshing that out in the near future.

I suppose with the addition of the Vim pages on the right side of this page, I can say that I’ve now “begun” my new blog. I’ve had others in the past that were all pretty stupid, but I’m trying to make a commitment to Vim, to write about it, Screencast it, and Twitter it.

Watch this space…

Oh now this is sweet, ladies and gentlemen. Wordpress has the BlackBerry client. I’ll be playing with this… Cheers Wordpress!