Archive for July 2012

Vim mode in Irssi

I came across an Irssi script that provides vim-like keybindings for the input line.

The script allows you to toggle between INSERT, COMMAND and EX modes.

In my vimrc and zshrc, I’ve already got jj mapped to Esc when in INSERT mode. The Irssi script provides this mapping by setting:

/set vim_mode_cmd_seq j

Another useful feature is the mode indicator, best used in conjunction with uberprompt.

From the README, the following common keybindings are supported:

  • Command mode: Esc <Ctrl-C>
  • Cursor motion: h l 0 ^ $ <Space> <BS> f t F T
  • History motion: j k gg G gg
  • Cursor word motion: w b ge e W gE B E
  • Word objects: aw aW
  • Yank and paste: C<y p P>
  • Change and delete: c d
  • Delete at cursor: x X
  • Replace at cursor: r
  • Insert mode: i a I A
  • Switch case: ~
  • Repeat change: .
  • Repeat: ftFT: ; ,
  • Registers: "a-"z "" "0 "* "+ "_
  • Line-wise shortcuts: dd cc yy
  • Shortcuts: s S C D
  • Scroll the scrollback buffer: Ctrl-E Ctrl-D Ctrl-Y Ctrl-U Ctrl-F Ctrl-B
  • Switch to last active window: Ctrl-6/Ctrl-^
  • Switch split windows: <Ctrl-W j Ctrl-W k>
  • Undo/Redo: u Ctrl-R

Get the script at:

SSD + GPT + grub2 + systemd

Summary of my new Arch setup optimised for SSD. See ArchWiki for more tweaks.


  • Specs: GA-EP45-DS3L, C2D E8400, 4GB DDR2, 512MB HD4850, 1x 640GB WD Black, 2x 1TB WD Green
  • Purchased: 120GB Intel 330 SSD

BIOS/UEFI settings

  • Firmware: EFI/UEFI instead of BIOS
  • SATA Mode: AHCI instead of IDE

Pre Installation

  • Partition: GPT instead of MBR

Arch Installation

  • Filesystem: ext2 for /boot; ext4 for the rest
  • fstab options: noatime, discard
  • Bootloader: GRUB2 instead of GRUB1/GRUB Legacy

Post Installation

  • Init: systemd instead of sysvinit
  • I/O scheduler: noop instead of cfq

Misc Output

systemd-analyze, gdisk, df, fstab, ls:

Udev: Changing SSD’s default (CFQ) I/O Scheduler

Courtesy of falconindy @ #archlinux

# set a larger readahead size
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/read_ahead_kb}="1024"
# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"

To verify:

$ cat /sys/block/sda/queue/scheduler
noop [deadline] cfq

ALSA: Switch audio output to USB Headset

I recently purchased a USB headset.
Here’s how to get it working with ALSA, manually and automatically.


(From ALSA ArchWiki)

Load module:

# modprobe snd_usb_audio

Verify that module is loaded:

$ lsmod | grep snd_usb_audio
snd_usb_audio          93519  3 

Find corresponding card ID:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 2: P780 [Plantronics GameCom 780], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Set card ID as default audio device in ~/.asoundrc:

defaults.ctl.card 2
defaults.pcm.card 2

The manual method works fine if the headset is always plugged in.


It would be better if we could automatically change the default audio device based on whether the USB headset is plugged in or not. This can be achieved by using udev rules.

Add the following to /etc/udev/rules.d/00-local.rules:

# Set USB headset as default sound card when plugged in
KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"

# Restore default sound card when USB headset unplugged
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"

udev automatically detects changes to rules. However, you will need to unplug and replug the headset for changes to be be triggered.

Audio applications need to be restarted whenever default card changes. If anyone knows a way of switching audio devices without restarting applications (using ALSA, not Pulseaudio), please let me know.