Wednesday, November 26, 2008

AwesomeWM

I've used a lot of window managers and desktop environments over the years (Gnome, KDE, Window Maker, Blackbox, Fluxbox, Enlightenment, XFCE, etc...). The last few years, I've lost a lot of motivation to experiment and stuck with the OS default (Gnome/Metacity in my case). Recently though, I've been increasingly trying to avoid ever touching the mouse. This is partially due to wrist issues and partially just to try and be more efficient. The quest for a mouse free lifestyle lead me to find the aptly named Awesome Window Manager.

If you're like me and have used many window manager, you're probably groaning right now and saying, "what makes Awesome any different from my current window manager?" Well, quite a few things actually. For one, Awesome is a tiling window manager. This means that if you open three terminal windows on the same screen, the WM will neatly organize them on the screen in an intelligent fashion. If you don't like the tile layout, you can switch layouts with a keystroke. If you want a certain application to fall outside of the default tiled layout, you can set it to float, and it will behave like it would in any other window manager.

While tiling is nice, it's not the only thing that makes Awesome unique. Awesome also avoids the traditional concept of virtual desktops or workspaces in favor of a tagging mechanism. Tags allow you to assign applications to logical groups in which they will appear together. An application can be bound to any number of tags. Even better, tags allow you to assign rules to newly opened applications, so I can say, "Firefox will open on the `Firefox' tab in floating mode on my 2nd monitor". You can also assign a default layout and number of columns to a given tab for tiling. Last but not least, each monitor can have it's own tagset giving you the equivalent of an independent session per monitor.

This is all good and well, but what does it have to do with getting around with the keyboard? Well, quite a lot actually. Awesome allows you to setup keybindings to navigate between tabs, send applications to a given tab, switch between applications on a given tab, resize windows, rotate windows within the tileset, jump between monitors, etc. All this is done inside of your awesomerc file, and the syntax is very straightforward. In my custom configuration, I've setup Awesome to respect keybindings very similar to Vim, so I can jump between monitors and windows using a combination of my meta key (windows key), a modifier (alt), and H, J, K, and L. As a bonus, it also happens to be extremely fast with performance in the same class as fluxbox and it's cousins.

A final feature that I've come to absolutely love is it's widget support. There's a user configurable statusbar that by default contains your current tagset listing and a small layout diagram. The rest of the statusbar is essentially open for whatever you want to add. All an application has to do to update the statusbar is write to standard output, so I've constructed a series of shell scripts to show the current time, CPU usage, memory usage, active users, and active streams at Grooveshark. All of these are basically one-liners. Here's my clock for the sake of example:


#!/bin/sh
while true
do
echo "0 widget_tell mystatusbar clock text " \
"`date +"%A %B %d, %Y %l:%M %p"`" | awesome-client
sleep 1
done


In case I missed anything, here's the laundry list of features from the Awesome website.

* Very stable, fast, small and simple;

* Only window manager using asynchronous XCB library instead of the old synchronous Xlib: make awesome faster than any other window manager;

* Very well documented source code and API;

* No mouse needed: everything can be performed with keyboard;

* Real multihead support (XRandR, Xinerama or Zaphod mode);

* Implement many Freedesktop standards: EWMH, XDG Base Directory, XEmbed, System Tray;

* Some real transparency support (using Composite extension and xcompmgr);

* Doesn't distinguish between layers: there is no floating or tiled layer;

* Whether or not the clients of currently selected tag(s) are in tiled layout, you can rearrange them on the fly. Popup and fixed-size windows are automatically floating.

* Layout handling: automatically manage your windows placement according to the chosen policy for each tag;

* Use tags instead of workspaces: allow to place clients on several tags, and display several tags at the same time;

* A lot of Lua extensions to add features: dynamic tagging, widget feeding, tabs, …;

* D-Bus support;

* And more.

And of course a screenshot is worth a thousand words.

awesome screenshot

And Finally, The AwesomeWM Website.

[edit]
As requested, here's a copy of my awesomerc. Note that I'm using version 2.3.4.

Tuesday, November 25, 2008

Reload VIMRC

You can quickly and easily reload your vimrc with the following command.

:source $MYVIMRC

If you want to know what your current vimrc is, just do the following.

:echo $MYVIMRC

Tabs

It took tabs a while to grow on me when using Vim. This is mainly due to the flexibility that buffers and split windows provide; however, once I realized tabs could act as a convenient way of grouping split windows, I was sold. There's nothing complicated or confusing about using tabs, but a few mappings will make your life easier. Add the following to your vimrc.

let mapleader = ","
map <leader>tt :tabnew<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>tn :tabnext<cr>
map <leader>tp :tabprevious<cr>

I've already been called a n00b once on this blog for not seeing the value of the comma motion (repeat latest f, t, F or T in opposite direction). If you use it regularly, you'll obviously want to choose a different map leader.

Now that your mappings are setup, using tabs should be quick and intuitive.

* Press ,tt to open a new tab
* Press ,tc to close the current tab
* Press ,tm [number] to move to tab [number]
* Press ,tn to move to the next tab
* Press ,tp to move to the previous tab

In standard Vim, the tab list will appear at the top of your editing window. Gvim provides the industry standard GUI tabs. Obviously there are more tab commands available, but these basics should get you pretty far.

Friday, November 21, 2008

Using a Mapleader

As you have probably realized, keyboard real estate in Vim is pretty heavily occupied in normal mode. Specifically, just about every key is already bound to a command. Luckily, Vim provides a facility to define additional mappings on these keys. It's called a mapleader, and it's easy to setup.

First you need to define what key you want your mapleader to be. I prefer comma because it's (in my daily usage) unused, and it's easy to reach. Add the following to your vimrc.

let mapleader = ","

Now that mapleader is defined, you can use it for custom mappings at will.

:map <leader>n :new<cr>

Press `,' then `n' in normal mode, and it splits to a new window.

:map <leader>i I

Press `,' then `i' in normal mode, and it puts you into insert mode on the first character of the current line.

These usage examples are slightly obtuse, so I'll be showing how to incorporate using a mapleader into tab management in an upcoming post.

Thursday, November 20, 2008

Share a Screen Session

It's possible for two users to share a screen session. This is particularly useful if multiple people want to monitor a long running task, and it's easy to do.

user #1:

screen -R longbuild

user #2:

screen -x -R longbuild

The -x flag tells screen to allow you to attach to an already attached session. This is also good for crazy stuff like a collaborative Vim session (if you're into that sort of thing).