VI Tricks

VI is a text editor that comes on pretty much every *nix box on the planet.  It can be your friend or it can be a difficult beast to wrestle with.  The interface on it is *not* intuitive at all but it is extremely powerful.  You can do things in VI that can only be done with some sort of regex otherwise. 

For example, if you want to remove all the blank lines from you code before you start to compress it…

  1. Open your document in vi
  2. Get your edit prompt by hitting ESC
  3. Type this in:  %s/^$//g
  4. Hit enter & you’re done

If you don’t have dos2unix on your box, and you need get rid of the ^M’s Windows puts in everything…..

  1. Open your document in vi
  2. Get your edit prompt by hitting ESC
  3. Type this in:%s/<CTRLV><CTRLM>//g
  4. Hit enter & you’re done

If an error message is giving you a specific line of code, you set line numbers to show……

  1. Open your document in vi
  2. Get your edit prompt by hitting ESC
  3. Type this in: set nu
  4. Hit enter and line numbers will magically appear

Want to jump to the line that you’re looking for instead of scrolling…..

  1. Open your document in vi
  2. Get your edit prompt by hitting ESC
  3. Type this in:#G where # is the line number
  4. Hit enter and hit your destination
  5. You can get to the top by using 0G (that’s a zero) and to the end by using G by itself

Need to delete an entire block of text, no problem……

  1. Open your document in vi
  2. Get your edit prompt by hitting ESC
  3. Type this in:dd# where # is the number of lines of text you want gone
  4. Hit enter and it will magically disappear
  5. If you want to move it, navigate through the document until you get to where you want it and hit “p”

Open Source Dork-O-Rama

One of the biggest complaints about Linux is that it’s hard to use.  I have to say that I tend to agree with this, especially when the package maintainers loose their freaking minds.  Yes, as hard as it is for me to admit some times, even IT geeks can be dumbasses. 

What am I on about you ask?  Well, we recently upgraded two of our servers here.  They run what has become a particularly problematic version of Linux called Gentoo.  Now, I want to be clear here.  I’m not poking at all Linux.  I’m a huge proponent of *nix, but I’m more of a FreeBSD fan myself, since it is just as free (dollar-wise) as Gentoo and maintained by a group of people I consider to be far more sensible.  It’s also a true Unix operating system, much like many of the high end things I operate at work. 

The upgrades were necessary to maintain the security of these servers since they’re exposed to the internet.  The people who make the install package for the shiny new version of Apache, our web server, have decided that they suddenly do not need to include the basic modules that Apache uses in order to operate – little things like mod_auth that are enabled by default because everything in the world ties into them. 

After several hours of hacking on what should have a 10 minute thing, I’m going to have say that I’m most displeased.  Why anyone in their right mind would remove things that are vital to the function of the server is beyond me.  They need to step away from the crack pipe.