Mark i3 Windows and Navigate Marks


Here's how to mark or label a window and focus on that window by mark name.

What is usual and obvious in much i3 documentation and blogging is how to navigate directionally (focus the window to the top, left, etc). Most i3/configs include examples for these bindings. But there is a fabled way of navigating to pre-existing windows using i3 marks, jumping to exactly what you want. What are i3 marks, and how is this done?

i3 Marks

A mark is a label that you can put on a window. It's a way to identify what's in the window.

To mark a window, use the mark command (or i3-msg mark command if outside of the i3 context).

To see a mark, look in the top-right corner of the window title bar. It will be a small, gray, lowercase letter, surrounded in square brackets. Note that you must not have hidden window title bars to see this, obviously(?).

To move focus or jump to a window, you must target it. You can do that with the a selector like [con_mark=myMarkName] and then use the focus command.

Script i3 Marks with Dmenu

If you're in i3, there's a good chance you're also using dmenu. Here's a great method for marking windows using dmenu, this gem from i3-wm-scripts.

First, make a script to mark your windows, in a file called imark:

#!/bin/sh -ue
name="$(i3-msg -t get_marks | tr -d '[],' | sed -e 's/""/\n/g' | tr -d '"' | dmenu -p mark)"
exec i3-msg mark "$name"

Here's the breakdown:

  • i3-msg -t get_marks - get all the marks i3 knows about; -t sends an ipc message, of which get_marks is one
  • tr -d '[], - tr for "translate"; -d for deleting all characters listed: brackets and commas, since get_marks returns an array or quoted strings
  • sed -e 's/""/\n/g' - replaces double quotes between tags with newlines
  • tr -d '"' - remove final quotes and beginning and end
  • dmenu -p mark - show dmenu with prompt of "mark", allowing input, listing all the existing marks
  • exec i3-msg mark "$name" - tell i3 to mark the window with the name entered in dmenu

Next, a script to jump to a mark, called igo:

#!/bin/sh -ue
name="$(i3-msg -t get_marks | tr -d '[],' | sed -e 's/""/\n/g' | tr -d '"' | dmenu -p focus)"
i3-msg "[con_mark=$name] focus"
  • Same dmenu buildup as above
  • i3-msg "[con_mark=$name] focus" - tell i3 to focus the window with the mark selected from dmenu

Launch with dmenu

Once you have the two scripts set up, you can launch with dmenu really easily. You can launch anything that's inthe $PATH. Active dmenu and type either imark or igo

Launch with i3

But since these are i3 control scripts that we've set up, it would make a whole lot of sense to let i3 control the launching of the scripts, which we can do in ~/.config/i3/config bindings:

bindsym $mod+m exec imark
bindsym $mod+g exec igo

Sooo slick!

Any other i3 mark tips? We need more of this.