ArchLinux Tutorial, Part 3: i3 Configuration and Operation

DZone 's Guide to

ArchLinux Tutorial, Part 3: i3 Configuration and Operation

The the last of these tutorials, we take a look at installing and configuring i3 in ArchLinux and what you can do with it.

· Open Source Zone ·
Free Resource

Image title

Part 1: Basic ArchLinux Installation

Part 2: X Window System and i3 Installation

Part 3: i3 Configuration and Operation

In the last two posts, we covered a base ArchLinux installation on bare-bones hardware and X Window Server installation and basic configuration.

In this post, we will cover the i3 Window Manager Configuration and we will cover some configurations for the ranger file manager.

What is an i3? i3 is a tiling window manager. i3 is one of the fastest and customizable window managers that focuses primarily on efficiency and productivity. i3 provides a very different user experience compared to most common desktop managers like GNOME, KDE or even XFCE. The learning curve is steep, but once you get accustomed to a plethora of shortcuts, you will be surprised how efficient and productive the desktop environment can be.

First, let's configure i3 start   when we are starting Xserve.

configure ~/.xinit.rc


# ~/.xinit.rc


# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"

if [ -d /etc/X11/xinit/xinitrc.d ] ; then
 for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
  [ -x "$f" ] && . "$f"
 unset f

exec i3

The first time you start i3, it will ask you a few questions to select a management key (primary key to manipulating windows and i3 environment), and you have two selections, Windows Key or Alt Key. By default, i3 operates with Windows Key, and I recommend sticking with the default option.

Once i3 is started, it will create a configuration file in used ~/.local/i3 directory where you can configure all the necessary keybindings to get most of the i3 promised efficiencies.

A good start with learning the available options is the i3 official website and, specific for ArchLinux users, the i3 Arch Linux Wiki.

i3 KeyBindings

By default, i3 comes with pre-configured keybindings. I am assuming you selected WinKey as your management key. i3 refers to WinKey as the "$mod" key.

Open new Terminal


You can try to open multiple terminals and to move between terminals without touching your mouse. i3 comes with vim key bindings.

Focus on Left Window WinKey+j
Focus on Right Window WinKey+;
Focus on Below Window > WinKey+k
Focus on Upper Window WinKey+l

You can use the directional keys to navigate.

Window Position

Opening Application Windows we can arrange in a few ways.

Arranged Vertically

Image title

Arranged Horizontally

Image title

Arranged in Mix mode

Image title

Windows Manipulation

Assuming we may have multiple windows open and you would like to focus on a single window, you can use this shortcut

Window full screen WinKey+f

i3 is sizing Windows, and every window gets an equal amount of space. But you can still manage your windows in 3 types.

split vertically and split horizontally WinKey+e
get a list of windows at the top WinKey+s
position Windows at the top similar to tabs WinKey+w

i3 doesn't provide a start button where you can launch the application. To start the application, you can use dmenu and pick from the list of installed application to launch.

Start application WinKey+d

Another way to start an application that may not appear in dmenu is this shortcut:

Start application


Any time you open a new application will open in a new window on the right of the active window. If you intend to open a new window below an active one, you will need to let i3 know.

Focus to open a new window in vertical mode WinKey+v

Now you can open the application, and this will open this active window:

Focus to open a new window in default horizontal position WinKey+h

i3 provides virtual desktops called workspaces. So as not to clutter the desktop, you can open the application in a chosen window using WinKey and a number from 1 to 0.

Select desktop 1 WinKey+1
Select desktop 2 WinKey+2
Select desktop 3 WinKey+3

Select desktop 4


Select desktop n


Move the open application window to a new workspace

Select windows and move to Desktop 2 WinKey+Shift+2

In some cases, users may want to make application windows behave similarly as standard desktop windows that can be moved across the desktop in different positions. This can be done in i3 by evoking a floating window.

On selected windows make it floating WinKey+Shift+Space

If you want to allocate more desktop space for one of the applications, you can resize it.

Enter into the resize mode 


Once in resize mode you can extend or contract active window both vertically and horizontally.

Horizontal active window resize WinKey+j or WinKey+:
Vertical active windows resize WinKey+k or WinKey+l

Instead of jusing the letter keys, feel free to use the directional keys.

Restarting i3 WinKey+Shift+r
Exiting i3 WinKey+Shift+e

For a more detailed explanation and additional configuration options you can find what you need in the i3 user guide.

i3 already comes with tons of useful keybindings that can help us get more focused and get more productive, but we can enhance it even more.

By default, i3 starts with the status bar at the bottom, and on the right side, you can see system information that can be useful.

Let try to enhance the i3status bar to show us only needed information by editting the ~/.config/i3status/config file.

In below example, I configured my system to show CPU usage, CPU load, disk space used in %, IP address, sound, volume, and time.

# ~/.config/i3status/config

general {
        colors = true
        interval = 3

order += "cpu_usage"
order += "load"
order += "disk /"
order += "ethernet _first_"
order += "volume master"
order += "tztime local"

ethernet  _first_ {
        # if you use %speed, i3status requires root privileges
#        format_up = "E: %ip (%speed)"
        format_up = "eth: %ip"
        format_down = "E: down"

cpu_usage {
        format = "CPU %usage "

tztime local {
        format = "%Y-%m-%d %H:%M:%S"

load {
        format = "%1min %5min %15min"

disk "/" {
  format = "Used / %percentage_used"
  separator = false

volume master {
        format = "♪: %volume"
        format_muted = "♪: muted (%volume)"
        device = "default"
        mixer = "Master"
        mixer_idx = 0

Image title

It is time to do some small modifications to the i3 config file to get some additional functionality.

Edit~/.config/i3/config and add these changes to your configuration. In some cases, you may need to comment the original setting.

# Change Font
font pango:monospace 10

# Move status bar on top
bar {
        position top
        status_command i3status

# Add gaps between windows look nicer
gaps inner 5
gaps outer 5

# Mouse, please stop focus whenever you hover to whatever
focus_follows_mouse no

# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# Enable floating dialogs application window
for_window [window_role="pop-up"] floating enable
for_window [window_role="task_dialog"] floating enable

# Key bind for Alsa sound
# Note: My keyboard has dedicated buttons that it is mapped to alsamixer
bindsym XF86AudioRaiseVolume exec amixer -q sset Master 5%+ unmute
bindsym XF86AudioLowerVolume  exec amixer -q sset Master 5%- unmute
bindsym XF86AudioMute exec amixer -q sset Master toggle

bindsym $mod+= exec amixer -q sset Master 5%+ unmute
bindsym $mod+- exec amixer -q sset Master 5%- unmute

bindsym $mod+x [urgent=latest] focus

# num lock activated
exec_always --no-startup-id numlockx on
exec_always --no-startup-id conky

# Assign application to start on a specific workspace xprop
assign [class="^Firefox$"] 1
assign [class="^Slack$"] 3
assign [class="^Code$"] 2
assign [class="^Vlc$"] 9
assign [class="^Spotify$"] 10
for_window [class="Spotify"] move to workspace 10
for_window [class="^Slack$"] floating enable

# Restart or shutdown or suspend by using WinKey+Pause key with meny to select option
set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown
mode "$mode_system" {
    bindsym l exec --no-startup-id $Locker, mode "default"
    bindsym e exec --no-startup-id i3-msg exit, mode "default"
    bindsym s exec --no-startup-id $Locker && systemctl suspend, mode "default"
    bindsym h exec --no-startup-id $Locker && systemctl hibernate, mode "default"
    bindsym r exec --no-startup-id systemctl reboot, mode "default"
    bindsym Shift+s exec --no-startup-id systemctl poweroff -i, mode "default"  

    # back to normal: Enter or Escape
    bindsym Return mode "default"
    bindsym Escape mode "default"

bindsym $mod+Pause mode "$mode_system"

# Custom Keybindings

# Shortcuts to start application
bindsym $mod+Ctrl+f exec --no-startup-id firefox
bindsym $mod+Ctrl+v exec --no-startup-id vlc
bindsym $mod+Ctrl+c exec --no-startup-id chromium
bindsym $mod+Ctrl+r exec --no-startup-id urxvt -e ranger

# lock PC
bindsym $mod+Ctrl+Delete exec $Locker, mode "default"

# Change you $USER home director and you may need to install packages imagemagick xclip 
# take a screenshot of a screen region and copy it to a clipboard
bindsym --release Shift+Print exec "/home/mudrii/.local/bin/screensh -s /home/mudrii/Images/"

# take a screenshot of a whole window and copy it to a clipboard
bindsym --release Print exec "/home/mudrii/.local/bin/screensh /home/mudrii/Images/"

Often, I do not want to start my applications one by one and move to the correct workspace; I want to have a keybinding that allows me to start preselected, correctly formatted applications in a predefined workspace.

To achieve this it will create a script file that can be triggered by a key combination that will open the desired application in the predefined workspace and in a preselected position.

1. Open the selected application and position on your proffered workspace and run:

i3-save-tree --workspace 1 > ~/.config/i3/workspace_1.json && \
tail -n +2 ~/.config/i3/workspace_1.json | fgrep -v '// splitv' | sed 's|//||g' > ~/.config/i3/workspace_1.jso

The command above will create a workspace_1.json file with all information captured from i3, which you may need to review and edit if required.

2. Create a shell script that will import the configuration into i3.

Note: In below case, I am starting Firefox, Sublime and Terminal URXVT on workspace 1.


i3-msg "workspace 1; append_layout ~/.config/i3/workspace_1.json"

# And finally we fill the containers with the programs they had
(subl3 &)
(urxvt &)

3. The last step is to add a keybinding to ~/.config/i3/config.

bindsym $mod+Ctrl+1 exec ~/.config/i3/start_w1.sh

Once you are in i3, use WinKey+Ctrl+1 to open the predefined application in workspace 1. Repeat the same process for the rest of the application.

Image title

Desktop System Information with Conky

Conky is a tool that can display desktop system information like CPU, RAM, and HDD. The Conky configuration is in ~/.config/conky/conky.conf.

-- vim: ts=4 sw=4 noet ai cindent syntax=lua
Conky, a system monitor, based on torsmo
Any original torsmo code is licensed under the BSD license
All code written since the fork of torsmo is licensed under the GPL
Please see COPYING for details
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

conky.config = {
    own_window_transparent = true,
    own_window_argb_visual = true,
    own_window_argb_value = 255,
    double_buffer = true,
    alignment = 'bottom_right',
    background = false,
    border_width = 2,
    cpu_avg_samples = 2,
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',
    draw_borders = false,
    draw_graph_borders = true,
    draw_outline = false,
    draw_shades = true,
    use_xft = true,
    font = 'Roboto Mono:size=14',
    gap_x = 20,
    gap_y = 50,
    minimum_height = 5,
    minimum_width = 5,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_stderr = false,
    extra_newline = false,
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'override',
    stippled_borders = 0,
    update_interval = 5.0,
    uppercase = false,
    use_spacer = 'none',
    show_graph_scale = true,
    show_graph_range = true

conky.text = [[
${color white}Uptime: ${color white}$uptime
${color white}CPU:$color $cpu%
${color white}RAM:$color $mem / $memmax
/root: $color${fs_used /} / ${fs_size /}

To see Conky for i3 add the below line to ~/.config/i3/config.

exec_always --no-startup-id conky

Image title

Ranger File Manager

Ranger is a text-based file manager written in Python. Directories are displayed in one pane with three columns. We can configure Ranger to look more like the Midnight commander Unix users may be familiar.
Most of the keybindings in Ranger are very similar to VIM. If you are VIM users, Ranger will fit like a glove and if you are not, this is an excellent opportunity to get acquainted.

Let's deep dive into the configuration options.

Once installed ranger let's generate configuration files.

ranger --copy-config=all

This command will generate 5 files:

  • commands_full.py 

  • commands.py 

  • rc.conf 

  • rifle.conf 

  • scope.sh

Let's focus first on default keys to manipulate files with the Ranger.


Ranger uses many of the same keybindings as vim.

Key Description
j Move down
k Move up
h Move to the parent directory
gg Go to the top of the list
G Go to the bottom of the list
<Ctrl>+f Page down


Page up
J Page down 1/2 page
K Page up 1/2 page
H Go back through navigation history
L Go forward through navigation history

There are also some directory-specific shortcuts to move to common directories:

Key Description
gh cd ~
ge cd /etc
gu cd /usr
gd cd /dev
go cd /opt
gv cd /var
gm cd /media
gM cd /mnt
gs cd /srv
gr cd /
gR cd to ranger's global configuration directory

Working With Files

Ranger allows you to perform many different operations on files from within its interface.

Key Description
i Display file (useful if you'd like to view a text file in a pager instead of editing it)
l or E Open file (opens file in default file-handler)
r Open file with… (allows you to choose a program to use)
o Change sort order (follow by a character in menu selection)
z Change settings (commonly used toggle settings)
zh View hidden files ( . files)
<Space> Select current file
t Tag file (you can perform actions on tagged files)
cw Rename current file
/ Search for files
n Jump to next match
N Jump to the previous match
yy Yank (copy) file
dd Mark file for cut operation
<Delete> Delete selected file

Tabbed Browsing

Ranger also incorporates tabbed functionality to allow multiple viewports into the filesystem.

Key Description
<Ctrl>+n Create new tab
<Ctrl>+w Close current tab
<Ctrl>+~ View Both Tabs in same windows
<Tab> Next tab
<Shift><Tab> Previous tab

General Commands

These commands control Ranger itself:

Key Description
? View ranger man page
1? Keybindings help
2? Command help
3? Settings help

Reload current directory

Q Quit

Command Interface

Like VIM, Ranger also includes a robust command interface. This allows you to manipulate files in more complex ways.

Key Description
! Execute a command from the shell (non-ranger commands)
: Execute a ranger command
du Measure disk usage of the current directory
chmod Change permissions of the current file

There are a number of flags that you can pass to commands to modify the operation of the commands. They should be used with a dash "-" after typing "!" for shell commands or ":" for Ranger commands:

Key Description
-s Discard the output of the current command.
-d Detach the process and run in the background
-p Return the output in ranger's file pager
-w Do not return immediately after command execution. Hang until "Enter" is pressed
-c Perform command on the current file, not the selected files

Ranger also allows you to target specific files by substituting groups of files for command operations. It accomplishes that by using placeholders that will be expanded with the correct files upon execution:

Key Description
%f Substitute highlighted file
%d Substitute current directory
%s Substitute currently selected files
%t Substitute currently tagged files

For example, if we wanted to change the names of multiple files, we could select them all with the space bar. After that, we can type:

:bulkrename %s

Once you get familiar with the Ranger operational mode, you can make some small changes to the Ranger and get more customized to our needs by editing main configuration file ~/.config/ranger/rc.conf

Note: In the below output, only changes and addons are pasted.

# Show hidden files? You can toggle this by typing 'zh'
set show_hidden true

# Be aware of version control systems and display information.
set vcs_aware true

# Use one of the supported image preview protocols
set preview_images true

# Set the preview image method. Supported methods:
set preview_images_method w3m

# Which colorscheme to use?  These colorschemes are available by default:
set colorscheme solarized

# Draw borders around columns?
set draw_borders true

# Save tabs on exit
set save_tabs_on_exit trueq

# Send to trash with single command
map DD shell mv %s /home/${USER}/.local/share/Trash/files/

Let's add more functionality to cleanup trash by editing~/.config/ranger/commands.py.

# Empty Trash folder command :empty
class empty(Command):

    Empties the trash directory ~/.Trash

    def execute(self):
        self.fm.run("rm -rf /home/mudrii/.locale/share/.Trash/{*,.[^.]*}")

You can find more information on the Arch Linux Wiki Ranger page, and these config files can be found in my Github.

We just touched the surface of what is possible in i3. Every user may have a separate setup and desktop configurations and i3 is one of the most flexible and versatile window managers that provides full control over these settings. Feel free to explore and deep dive into countless possibilities i3 provides.

archlinux, desktop, i3, installation and configuration, linux, open source

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}