Results tagged “linux”

Being a long-time "vi" user I find that I am constantly surprised by the little (and not-so-little) enhancements vim has added. One of them is the "inner" concept.

Any vi user knows that "c" starts a c change and the next keystroke determines what will be changed. "cw" changes from where the cursor is until the end of the word. For example, "c$" chances from where the cursor is to the end of the line. Think of a cursor movement command, type it after "c" and you are pretty sure that you will change from where the cursor is to.... wherever you've directed.

"d" works the same way. "dw" deletes word. "d$" deletes to the end of the line. "d^" deletes to the beginning of the line ("^"? "$"? gosh, whoever invented this stuff must have known a lot about regular expressions).

VIM adds the concept of "inner text". Text is structured. We put things in quotes, in parenthesis, between mustaches (that's "{" and "}") and so on. The text between those two things are the "inner text".

So suppose we have:

<span style="clean">Interesting quote here.</span>

but we want to change the style from "clean" to "unruly". Move the cursor anywhere between the quotes and type ci then a quote (read that as "change inner quote"). VIM will seek out the opening and closing quotes that surround the cursor and the next stuff you type will replace it.

It works for all three kinds of quotes (single, double, and backtick), it works for all the various braces: ( { and <. You can type the opening or the closing brace, they both do the same thing.

Therefore you can move the cursor to the word "style" in the above example and type "ci<" to change everything within that tag.

I find this particularly useful when editing python code. I'm often using ci' to change a single quoted string.

If there is an "inner", you'd expect there is an "outer" too, right? (How many of you tried typing co" to see if it worked?) Well, there is an there isn't.

In VIM the opposite of "inner" is "block". A block is kind of special. It don't just include the opening and closing elements plus sometimes a the space or two that follow. Given this text:

  • The quick <span class="foo">>brown</span> fox.

If the cursor is in the <span> element, "cb<" will replace the entire element from the < all the way to the >. The whitespace after the element is also replaced for text-related things like change word (caw) and change sentence (cas).

Not having to move the cursor to the beginning of an element to change the entire thing is a great time saver. It is these little enhancements that makes using VIM so much more pleasant that using VI.

Give it a try!

More information about this is in the "Text Objects" section of Michael Jakl's excellent VIM tutorial.

--Tom

P.S. My second favorite thing about VIM? gVIM (The graphical version of VIM) preserves TABs when you use the windowing system to cut and paste.

Posted by Tom Limoncelli in Technical Tips

Lance Albertson wrote up a great description of how Ganeti Virtualization Manager performed under pressure during a power outage:

Nothing like a power outage gone wrong to test a new virtualization cluster. Last night we lost power in most of Corvallis and our UPS & Generator functioned properly in the machine room. However we had an unfortunate sequence of issues that caused some of our machines to go down, including all four of our ganeti nodes hosting 62 virtual machines went down hard. If this had happened with our old xen cluster with iSCSI, it would have taken us over an hour to get the infrastructure back in a normal state by manually restarting each VM.

But when I checked the ganeti cluster shortly after the outage, I noticed that all four nodes rebooted without any issues and the master node was already rebooting virtual machines automatically and fixing all of the DRBD block devices.

Ganeti is a management layer that makes it easy to set up large clusters of Xen or KVM (or other) virutalized machines. He has written a great explanation of what is Ganeti and its benefits too.

I use Ganeti for tons of projects at work.

Posted by Tom Limoncelli in Technical Tips

(Note: this post is not about you.  I swear.)

Someone once asked me what improvements they could make to their Linux Users Group (LUG).  New people came but never returned.

Two things I observed.

1.  New people didn't feel welcome.  Suggestion: Go out of your way to make new people feel welcome.  Have a designated person show up early and just say "hi" to everyone that walks in. (If you are the leader, don't do this yourself.  Delegate. Look around, find the person with the biggest smile, and ask them to do it.  Not all geeks are... how do you say... "camera friendly".)  Most of us are introverts and would be turned off by someone that tries to make small-talk, but just hearing someone say "hi" is great.  Have good signs on the doors so people know where to go.  Nothing makes new people feel unwanted like a lack of being told where your meeting is.  I once went to a meeting (not a LUG, but the issue is the same) only to discover that the web site listed the address, but not the specific room... or which building.  There were no signs telling me where to go.  Ugh.

2.  If you have a Q&A session, the moderator should never answer the questions.  People come to share and everyone wants their turn to show off.  A big mistake I see is that the moderator will answer each question then look around and say, "Does anyone else have anything to add?"  Nobody answers.  Gee, I wonder why.  Well, the moderator just expressed their dominance and anything else would be an affront to the leader.  Folks, this is an open source movement.  We all have power and knowledge and good stuff to day.  If you are the moderator, be the last person to speak. Sure you know the perfect answer, in fact I bet you have 5 points you'd like to make.  However, so do other people in the audience.  Get them to say the answer.  Let a couple people speak.  After 3-4 people speak it is likely that 4 of the 5 points you wanted to make have been made already.  Now you can chime in with your 5th point.  Everyone else got their chance to shine and your 5 points were made.  You'll still look brilliant for having a 5th point that nobody else thought of, but you won't look overbearing.

Those are the top 2 problems I've seen.

The #3 issue is "Where to advertise?"    Please post a comment if you have suggestions.

Posted by Tom Limoncelli in Community

1

Credits