 i3 is my favorite window manager. I've made many videos about i3 over the last couple years and I will probably make many many more just because it is the best window manager and I firmly believe that. But that's not really why we're here today. I could go on and on about how amazing i3 is and all that stuff. But if you're new to i3 or you're considering to use i3 and one of the things that you need to know how to do is how to use it with multiple monitors, what are you to do? Well you could Google it. There are a lot of guides out there and there's excellent documentation for i3 but I figured I'd make a video about how to do it like a professional because there is a special way you can do it that makes it so easy to manage your workspaces across any number of monitors. So that's what we're going to do today. How do you manage i3 with multiple monitors? Let's go ahead and jump in. So what you need to do first is open up your i3 configuration file. So if you haven't used i3 at all before you can find this in .config slash i3 or in some cases it's in your home directory under a folder called .i3. Usually it's in .config. Mine's in different places and mine will look different than yours simply because I've done a lot of customizing so just kind of follow along as best you can because really what I'm going to show you isn't all that different no matter how your configuration looks like. So the first thing you need to do is define your monitor variables. So you can do this for any number of monitors. If you have two monitors like I do or you have three or four or six or ten how many of your monitors you have it doesn't matter. What you need to do first is set your monitor variables. So this is done using the set command inside your i3 configuration file. So as you see here I have set in the name of the variable and then the name of the monitor. So if you don't know how to find the name of your monitor let me actually show you how to do this. Let me turn my face off. You can do this by using the Xrander command. So just do Xrander like so and this will show you the name of the monitors that are active on your system. So I have display port one and I have HDMI-A-1. Every single monitor that is active on your system will have a list of screen resolutions that has available to it. That's how you know that it's active. It also will say that it's connected. So this is what you need for that variable. This name right here. And you want to make sure that you pay attention to capitalization because it has to be exactly the way it is listed here in order for it to work. Now one thing that you should know is if you use i3 on multiple computers it's a possibility that your monitor names change. So if you enter a situation where you're using i3 and all of a sudden your workspaces are all over the place check and see if the names of your monitors have changed and then update the variables as needed. So once you've created your variables like I've done here. So I have these two lines here are defining the variables and you can name them the variables whatever you want. I have FM and SM. So first monitor, second monitor. It doesn't really matter what you call them just long as you remember what you called them in the first place. So once you've done that the next thing you need to do is define your workspaces. So I have this in an included file up here called workspaces. So I'll go to this and what you need to do here is define where you want each workspace to reside. So for example I want workspace 1 through 9 to appear on the first monitor. So the first monitor is denoted by the variable FM. So I do workspace 1, output and then dollar sign FM which it calls the first monitor. So I do that for my workspaces 1 through 9 and then I want workspaces 10 through 19 on the second monitor. So I do workspace 10, output, dollar sign, SM. Now if I had a third monitor let's just say I had a third monitor I could do the same thing. So if I had let's just say workspace 20 and then let's pretend that I defined another variable called TM, third monitor. So I do output and then dollar sign oops dollar sign TM just like so and I could do that for any number of workspaces you want. The greatest thing about I3 is you can define as many workspaces as you want. You could have 100 workspaces if you have monitor space for those workspaces it really doesn't matter. And the cool way about doing it this way is that every set of workspaces is only ever going to appear on that monitor. Okay so workspaces 1 through 9 for me will only ever appear on this monitor right here. Workspaces 10 through 19 will only ever appear on my second monitor. They'll never float around no matter what. As long as those monitor variables don't change those workspaces will always be on the monitors where they're supposed to be. Once you've done this and defined all the workspaces you want, I'm going to delete that one there because I don't have a workspace 20, you needed to define the workspace variables. So all this does is gives the workspace numbers and assigned variables so you can call them later on if you want to. This is helpful for when you're doing your key bindings later on. If you use the i3 configuration file to do your key bindings I'll show you that in a minute. So once you've done this you're basically done. All you need to do next is actually assign key bindings to each of these workspaces and this is where the true magic happens because in most other tiling window managers it is a little bit difficult to assign key bindings to every single workspace especially when you have so many workspaces. So things like DWM you have to patch that functionality in and the patch that it was created is not all that great. With other window managers it's hard to even get more than nine workspaces. You have to kind of finagle in order to get that way. Either way usually when you have workspaces that act like they do on i3 where they kind of move around and are created on the fly it is a little bit hard to define key bindings that are associated with each workspace. However on i3 it is not hard at all so if I go back to my i3 configuration file like so I can define a key binding here for every single workspace that I have. So all you have to do and I don't actually have this in my i3 configuration file I'll show you what I do here in just a second but all you have to do is do bind sim so like this BINDSYM that's how you spell and then the key bindings that you want so mod in this case one plus one and then all you have to do is type in the workspace so you do something like workspace one like so however because we defined variables earlier we can just do ws1 and then we do this for every workspace that we have so we do one two three and fourth now here's the best part so once you've gotten through the key bindings for the first monitor so in my case it'd be one through nine what you want to do then is assign a key binding that is completely different for the workspaces that are on the other monitors so in my case what I'd want you to do is do bind sim dollar sign mod plus actually what we're going to do here is do mod one which is going to be the alt key I believe and then do one so this is alt plus one and then do dollar sign workspace zero or in this case I'm going to be workspace 11 so it'd be workspace 11 just like that and then you would do that for every single workspace that is on the second monitor and then if you had say a third monitor you could do bind sim dollar sign mod plus a shift if you wanted to like so and then the number so one and then it would be a dollar sign workspace 20 or whatever happened to be so as you can see the trick here is to assign a key binding that is different for each monitor so for me the way I do this and I'm going to undo all of this stuff here because I don't really need it I am going to show you my special sauce this is sx hkd and what sx hkd allows you to do is basically assign key bindings in one line so I have all my key bindings here in sx hkd I'm not going to show you how to do that I've made a video about that before but basically how this works is something like this so I have alt plus and then an array of numbers so 0 through 9 and then those numbers are associated with this command here i3 dash message which basically just passes a command 2 i3 basically as if it was in a configuration file and then workspace and then the number of the workspace so this one here applies to my second monitor for my first monitor I have it like here I have super plus 1 through 9 comma 0 i3 message workspace 1 through 9 comma 10 actually wrong because that needs part here needs to be deleted that was from when I was working with just 10 workspaces but the idea is the same right now obviously the more monitors you have the more complicated this gets because you obviously are going to run out of key bindings and you have to remember you also have to have key bindings for moving clients or windows or applications to certain workspaces so usually you use modifier keys for this to work so for me specifically I use shift so I do super shift 1 through 9 and that moves the container to one of those workspaces 1 through 9 I have alt shift 0 through 9 for workspaces on the second monitor if I were to have a third monitor I would use control shift 0 through 9 for the second monitor and I'd have to get creative for other key bindings because the more like I said the more monitors you have the harder finding key bindings is going to be and I highly suggest if you do have more than two monitors to use sxhkd because you can use key cords here in sxhkd and that will allow you to have some extra control and extra key bindings that you wouldn't get in the standard i3 configuration file so if we go back to my i3 configuration file and I show you this one last time bind sim sym dollar sign mod plus one workspace or in this case we're just going to do a dollar sign ws1 and then I do this for every single one that I have for one through nine so I'm going to yank this and then paste this a few times and then these are going to go up in numbers so and then I'd also change the variable obviously so what that would do is switch my focus from or between those workspaces and then I would want to do the same thing for the other monitors so I would do bind sim like so and then dollar okay then just mod one which is the alt key and then one and then workspace in this case I'm doing 11 I would do uh the zero the zero key for workspace zero I'll show you that here in a second so this is 11 and then I'm going to yank that a couple times and I'd also change the key so like so two three and that would take care of all of my bindings to move between all of my workspaces and like I said before if you have a third monitor all you'd have to do is come up with a third key binding so in this case you could use control if you wanted to so CTRL if you wanted to do that so it would be something like this so bind sim and then CTRL plus one and this would be workspace 20 and then you would do the same thing you just paste that a few times and then you change this so it it is two three four five and then this is going to be workspace 21 workspace 22 workspace 23 workspace 24 and so on and so forth like I said the more monitors you have the more complicated it gets now once you have all these you'll want to create modifiers using the shift key to control moving containers or windows or apps however you want to call them to each workspace so you do mod plus shift plus a number to move all your focus clients to workspaces one through nine mod one plus shift plus a number to move through workspaces 11 through 19 and so on and so forth i think that is a better way of describing this i tried to clarify a little bit because i don't think i did so well earlier but this way it actually shows you exactly how you would do it and obviously this gets messy that's the reason why i recommended using sx hkd if you know how to do sx hkd you can clean this up way easier so that is how you manage workspaces on multiple monitors in i3 window manager and obviously this works in i3 gaps to exactly the same if you have questions about any of this stuff you can leave those in the comment section below i'll try to answer them as well as i can i don't always have time to to help but when i do i do try to help as much as i can and i know that this can be confusing two monitors usually isn't all that much of a problem it's when people start to have three monitors that this gets way complicated and i think that my method of doing this makes it a little bit easier because if you don't assign those monitor variables there at the beginning your workspaces will move no matter where you are so if you are on your third monitor and you move to the next available workspace that's where the workspace will show up by assigning those variables you control where the workspaces are all the time so i have workspaces one through nine on first monitor that's where they'll always be they'll never move and the best part about all this is that because your mouse follows the focus so if you move to workspace 20 let's say you have a third monitor and workspace 20 is the first workspace on that third monitor if you have a key binding to move to that workspace and you execute that key binding your mouse moves over there with that key binding so that becomes the focus of your system and you can use your mouse you can spawn windows whatever same thing if you have a fourth monitor as long as you have a key binding for each and every workspace and that workspace is associated with a monitor once you've executed that key binding your focus moves to that monitor so like i said create a key binding for every single workspace it will then move your focus when you do that key binding and that makes this very very powerful so that is how you do it i can say if you have questions in the comment section below you can also ask me on twitter at the linuxcast you can follow me on mastdown or odyssey those links will be in the video description you can support me on patreon at patreon.com slash linuxcast just like all these fine people thanks to everybody who does support me on patreon youtube you guys are all amazing people i cannot even begin to say how thankful and grateful i am for your support so thank you so much thanks everybody for watching i'll see you next time