Thursday, April 14, 2011

QuickStart: VIM (Vi)


VIM (Vi IMproved) is installed by default, in one way or another, on most every flavor of UNIX and Linux. This is one of its best features. If you take a minute to learn it, you will be able to quickly edit text files from the command line on any *NIX box you come across. There are plenty of sites out there that list all the different vi commands, but they can be overwhelming. This post is meant to get you using vi and VIM, so I'll show you the basics.

First things first, to start the program, simply fire up a terminal and type vi.

synapsys@host:~$ vi

If you want to open up a particular file for editing, simply add the filename after the command.

synapsys@host:~$ vi examples.desktop


When vi first opens a file, it is in "command mode." In this mode we can issue commands to save, quit, etc. In order to change to "insert mode" we simply hit the "i" key. To return to command mode, hit the <Esc> key. Navigate to the spot that you want to edit with the arrow keys, then hit the "i" key to change to insert mode, then start typing. If you are getting characters like A, B, C, or D, when you press the arrow keys, you probably have a limited version of vi installed called vim-tiny (in Ubuntu.) To fix this, you will need to install the full version of vim. When you are done editing the text, press the <Esc> key to return to command mode. The only commands you need to know, for now, are as follows:

 :q!
  Quit without saving
 :w filename 
  Save as filename
 :wq
  Write changes to the file and quit 

If you want to open a new file for editing in vi, simply use this command:

synapsys@host:~$ vi newfile

That's it, you know enough to get started using this great program. For more information, see this site, and/or read the fine man page. 

Saturday, April 9, 2011

Review: Crunchbang Linux 10 "Statler"

Name:  Crunchbang Linux
Version:  10 "Statler"
Kernel:  2.6.32-5-amd64
Window Manager:  Openbox
Package Manager:  APT
Based on:  Debian

The installation was very quick and Debian-like. The whole process took 06:08.7 minutes from Live CD boot to installed desktop. At first boot, I was presented with a beautiful Openbox desktop


complete with conky already running and two virtual desktops. A post-installation script also pops up in a terminal window. This will first update the software sources, then update installed packages, then help you install additional software to your new Crunchbang system. The script will prompt you to install printer support, java, the Zen (possibly unstable) kernel, OpenOffice.org, SSHS & FUSE, multi-session support, version control software,  SSH Server, LAMP stack,  and various dev packages. This version of Crunchbang comes with the following software installed by default:

Terminal:  Terminator
File Manager:  Thunar
Web Browser:  Chromium
Media Player:  VLC
Text Editor:  Gedit

Crunchbang is not for the Linux noob, not everything works by default, and some things require a little tinkering. It also has a very clean menu-less and icon-less desktop, which is pretty, but not very beginner-friendly. Right-clicking on the desktop does give you a nice, customizable menu. There is also a list of shortcuts displayed by conky, which is very helpful. Crunchbang with Openbox has a nice look to it, which definitely appeals to the desktop minimalist. The default installation is <2GB not including the post-installation script packages, which is pretty small compared to most standard distributions. There are some packages like vi, however, that aren't fully installed, which is kind of annoying. I ended up having to install the full versions of some software before the system was totally usable for me.

Overall, Crunchbang is as fast as it can be without sacrificing much functionality. It fully boots, from power button to desktop, in 28.7 seconds, which is very respectable. It's not as fast as the little guys, but it has much more functionality. It doesn't have all the bells and whistles of the big guys, but it's much faster. I would definitely recommend it for installation on a netbook, or something with a SSD. It's also well suited for a Laptop or Desktop installation. Give Crunchbang a try, I guarantee you won't be disappointed...

HowTo: CSS code boxes

The easiest way to create boxes for code in your website is to use CSS. This can be done by setting up your own custom element, or by defining the <pre> tag. I like to use the <pre> tag because it obeys spaces and line breaks. This is fine as long as you don't want to use the <pre> tag for anything other than code boxes. The CSS code I use to define the <pre> tag for this blog is as follows:

pre {

      border: solid 1px gray;

      font-size: 1.3 em;

      font-family: 'Courier New', Courier, monospace;

      color: #FFFFFF;

      margin: 10px;

      padding:10px;

      text-align: left;

      background-color: #000000;

      overflow-x: auto;

      white-space: pre-wrap;

      white-space: -moz-pre-wrap !important;

      word-wrap: break-word;

      white-space: normal;

}


If you run a Blogger.com blog, you can easily add this bit of CSS to your template. From your dashboard click the "Design" tab, then "Template Designer." Then click the "Advanced" tab, and scroll all the way down to "Add CSS." Copy/paste this code (or your own modified version of it) into the box and then click "Apply to Blog." Now, whenever you want to insert code into a blog post, simply wrap it with <pre> and </pre> tags.

If you are wondering about the white-space and word-wrap entries, they are to ensure that word wrap is on for all browsers. I got them from here.