Learn tmux (Part 5) - How to Customize tmux and Make It Your Own!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] thank you hello again everyone and welcome back yet again to learn Linux TV for your team up series the updated version and we are at the final video in the series believe it or not we're at the end now don't be sad though there's so many Linux related videos on this channel that you couldn't possibly watch them all if you tried there's just not enough time and there's plenty of Linux content coming so you know what I'll be covering tmux again in the future I'm sure maybe I'll learn something new myself and then create a follow-up video you never know but what we're going to do in this video is make tmux extremely easy to use we're going to customize the shortcuts to make those our own we're going to install a color theme that I've prepared for you guys and you're just going to see all kinds of examples of customizing tmux we're going to make it all our own in this video it's going to be a ton of fun so let's just Dive Right In thank you so let's get started with customizing tmux now right now at this time I have no open sessions at all and that's important we want to start fresh because we're going to be creating a config file and we want tmux to open that config file and tmux only opens its config file when it's first opened even new sessions will continue to use the same config file until it's reloaded now that may not make sense right now but don't worry what we're going to do is just make sure that we have no sessions open we're going to start from scratch now before we even run tmux what we're going to do is create a very special config file using a text editor I'll use Nano for example we're going to edit this file right here in our home directory that's what the tilde is I have entire videos that goes over Linux file system Shenanigans and things like that but essentially what we're going to do is create a file in our home directory and we're going to call it tmux.conf our tmux config file and we definitely want this to be inside our home directory anyway I'll press enter and most likely you're going to have an empty file just like the one you see right here now the way this works is when tmux launches if it launches for the very first time meaning you have no open sessions it's going to read this file if it exists and load it into memory as long as you don't have any syntax errors or anything like that inside this file then tmux will honor any configuration you add to the file and make it take effect but right now we don't have anything inside this file so what should we add well I did mention earlier in the series that one of my goals is to help you make tmux easier to use and earlier I even described the process of using tmux as finger gymnastics because you're often going to be holding one key down while pressing another and if the keys are too far apart that's going to get a little tedious maybe even make your fingers a bit sore the thing is I'm not personally a fan of the defaults in tmux at all and I especially dislike the default prefix key as well so that's one of the first things I'm going to change in fact let's just change that right now what I'll do is paste in the code that we're going to use to create this customization and then I'll tell you exactly what it's doing and there it is now this might be a little confusing at first but it's really not all that bad what we're doing is we're setting an option within tmux and it's going to be a global option that's what Dash g means and we want to customize the prefix the capital c refers to control as you recall we've been holding Ctrl and pressing letter B to send the prefix to tmux that's the default but what we're doing here and we can see that in the first line is we're changing the prefix to be Ctrl J but what's up with the second line it shows prefix 2 being set to control F wait two prefixes well if you didn't already know you can have two prefixes inside tmux why would you want to do that well here's a good example I set the two prefixes to control F and Ctrl J and if you look at your keyboard if you are resting your fingers on the keyboard your index fingers are going to be resting on either F or J so if your right hand is busy then your finger is probably going to be resting on letter F vice versa for letter J on the other side of the keyboard so whichever keyboard side you are working on or whatever keyboard shortcut you're trying to execute you have a prefix key on both sides of the keyboard so that way you could use one or the other interchangeably depending on what shortcut you want to execute and this goes for anything that I showed you guys so far whether it's creating a split or anything else that requires the prefix to be entered or sent to tmux you could do that with a different prefix key altogether in this case I'm setting it to control J and Ctrl F you could use whichever one anytime you want now what we'll do is save the file and then we'll open up tmux and we'll just run through some of the things that we've done so far in the series we'll send the prefix but make sure you send one of the new prefixes so I'll just go ahead and do that right now and I created a horizontal split so instead of Ctrl B our default prefix key I used Ctrl F if I do Ctrl J there's no difference a prefix key is a prefix key it does the same thing regardless of what you set it to and if you don't personally like the default of control B then I highly recommend that you change it and that's exactly what we just did now I'm going to go ahead and log out completely I could just hold Ctrl and press D to disconnect from a particular pane or window that's not specific to tmux that's just a Linux terminal trick I'm going to keep doing that until I'm back to my main command prompt let's open up that config file yet again and add another customization now the reason why I decided to exit out of tmux is because again tmux will not read its config file until the next time it starts if I have an open session then technically tmux is running so it's not going to read its config file even if I launch a new session but let's make that a little bit easier and this is going to make the rest of the video a lot easier and what tweak am I referring to well what I'll do is paste it in right now and then I'll explain what it does and there it is and this is where things are going to get a lot more interesting with this configuration line right here is going to do for us is create a new shortcut as soon as we save this file we're going to have a new keyboard shortcut we can send prefix followed by R for reload and that's going to reload the tmux config file and we could do that without exiting tmux so from this point forward we no longer have to completely close out of every session just to load in a change to the sessions configuration and I'll go ahead and show you exactly what that looks like I'll save the file let's make sure that we have no team accessions open this will be the last time that we'll ever have to care about that and currently I don't have any open at all so we'll open up tmux and so far nothing looks different however if you send the prefix and then Type R now went by very quickly but if you pay attention to the very bottom of the screen you're going to see a message that confirms that the config file has been re-read into memory again with this customization we send the prefix and keep your eye on the bottom I was able to reload it so from this point forward we'll be able to configure tmux from within tmux itself in fact what I'll do is create a vertical split I'll go over here to the left hand side and I will open up that config file yet again and there it is now the next tweak that I'm going to show you is really really cool what we're going to do is add yet another configuration to this file and I'll paste it in right here and it says Mouse mode wait what's up with that well it's exactly what it sounds like let's save the file and we'll also reload tmux as well again we'll send the prefix we just added that customization so we should be able to do that anyway so prefix and then R4 reload and now tmux has been reloaded but what's changed well check this out I'm going to grab my mouse cursor I'm going to position it near this dividing line I'm going to hold down the left Mouse button and I'm just going to drag it check that out we have activated Mouse mode in every sense of the word but it doesn't stop there I could click on a pane to move my cursor directly into that pane so I could click on whichever one I want to start working with the same goes for horizontal splits as well same thing I can go ahead and resize this one I could drag this one up or down I could also drag this one to the right if I create another window I could go down here and click on the window that I want to go to immediately now you can also resize panes just like this by using the keyboard as well but it's a little convoluted but I prefer the mouse mode because it's a lot easier to use and that's usually the preferred way from most people that I've seen use tmux Mouse mode is very easy to do but if you want to implement a keyboard method then what you could do is check out the link in the description down below that'll lead you to the blog post for this video and there I'll have a complete tmux config file it'll even have comments within the file to help you understand what each customization does and among them will be keyboard shortcuts for resizing panes without using the mouse so for those of you that don't like using the mouse that'll be just for you but anyway we have enabled Mouse mode how cool is that if you're using a desktop Linux distribution this just makes everything so much easier especially if you're just starting out but speaking of making things easier let's Implement yet another tweak and you know what I'm going to paste several at once each of these are kind of related you'll see what I mean in a moment anyway I'll paste it in right here and I've added quite a bit more customization now I'm not going to go super in depth with how tmux configuration works you can look at the comments and see pretty much what it's doing just by looking at it I mean right here we're binding keys for example so this has to do with keyboard shortcuts but anyway what these customizations are going to do for us is make everything easier now I'll show you exactly what I mean let's just save the file and let's reload it now tmux is reloaded but what exactly did I change with this customization what are these keyboard shortcuts well let's go ahead and just close out of everything we don't have to do that but I think showing you what these keyboard shortcuts are going to do for us is going to be a lot more impactful if we see it from scratch so what I'll do his exit out of here I will save the changes so I'll disconnect disconnect disconnect disconnect disconnect and again we are now back to an empty terminal without tmux and on my end I no longer have any sessions open at all so I'll start one and we're here with an empty session as you can see so here's what we're going to do what I'm going to do is create a horizontal split I'm going to send the prefix key but I am not going to type the percent symbol like I did last time instead I'm going to type V for vertical done and for me that's a lot easier to remember again prefix letter V vertical it's easy to remember if you want a vertical split send the prefix type V and you're done when it comes to a horizontal split let me just close out of this one right here what I'll do is send the prefix and H for horizontal how easy is that and it's easy to remember H for horizontal V for vertical it works out for me anyway and that's the way that I prefer to use tmux those are the keyboard shortcuts that I use on a daily basis but that's not all that I've added to the tmux config file another tweak that I've added is I can now hold down alt and press the up Arrow to go up I can hold alt and press down to go down I can hold alt to press left to go left right to go right you get the idea so rather than sending the prefix before pressing an arrow key what you could do instead is just simply hold alt and then press an arrow key while you're holding that down and that just makes everything a lot easier and a lot quicker too but that's not all let's create another window and another one and why not create one more it doesn't matter how many we create we just need more than one now I showed you that I could use the mouse to switch between the tabs that I have open here or Windows I keep saying tabs but I think you know what I mean but the customization or at least one of them that I added gives you the ability to hold down shift and press left to go left hold down shift and press right to go to the window toward the right I could just cycle through each of these windows by holding down shift and just pressing the left and right arrows that makes it a lot easier to switch between them now you could argue that grabbing the mouse might be easier for some of you but since your fingers are on the keyboard I think that's the easiest way to do it all you have to do is just reach over hold down shift press one of the arrow keys and that's all there is to it so let's go ahead and reopen that config file and here it is we'll go to the end let's see what else we can add to this file and I'll paste the next one in right here and what this is going to do for us is give us the ability to easily just like the comment says here reorder windows let's save the file we'll send prefix and then type R for reload and let's see what we could do with this what we're going to do is hold down control as well as shift and press one of the arrow keys notice that the asterisk is down there at the bottom next to Nano and that particular window move to the left we're still on the window within the same position but by holding Ctrl and shift with this tweak and pressing one of the arrows whichever window you are attached to is going to be moved in the direction of the arrow key that you press so for example bash I'm going to move that to the left that essentially moves Nano back to its original position but you get the point you can now easily reorder the windows within our session now for another tweak I'm going to just enter a few times right here I'll paste it in and I'll save it and we can see here that it says synchronized pane so what does that mean exactly Well for now let's switch over to another window doesn't matter which one I just wanted a window that didn't have as much going on and what I'll do is create another pane so I'll send the prefix then H4 horizontal hold alt and press the up Arrow because we have that customization now I'll create yet another split this time I'll send prefix fee for vertical alt down arrow prefix B for vertical you get the idea and now we're using the customizations that we've implemented but I just added another customization and what exactly does that do well check this out what I'll do is send the prefix and then I'll type y and notice when I did that again that was prefix and then y it showed toward the bottom that synchronize mode has been enabled but what exactly does that do well I don't know I'll just type a command right here and see if anything's different and I'll press enter wait a minute I didn't know any better I would say that it's entering the same thing into each of the panes here and that's exactly what it's doing now I'm connected to the same server in each one of these panes so running the same apt command four different times on the same server is probably not a good idea but what if you are connected to several different servers maybe you want to execute the same command in each and what I'll do to illustrate this is connect to a server but first I need to disable synchronization mode otherwise I'm going to repeat everything and every pane right here just like you see so what I'll do is send the prefix then y again and now synchronization mode is disabled if I type I'm only typing in the pane that I have active so what I'll do is just connect to one of my servers here I'll just connect to my development server and now I'm connected to that server right there I'm going to go down here and close out of this pane I think I could get away with just two servers I think that's fine I'll close this one too now we have a connection to my development server here on the left and on the right I'm connected to my local footage PC but what if I wanted to run updates for example on both I'm not going to go through the process but I will show you a little bit of it just to show you what I'm talking about I'll activate synchronize mode again I'll send the prefix y that enables it that's what the customization does anyway and I'll go ahead and update these so I'll run sudo apt and then update so I'll press enter and I ran a command against two servers at the same time and I've done this with more than a dozen before it's very very useful if you're running maintenance and the maintenance that you're running is something that you need to run on a bunch of machines in your configuration management solution is not going to facilitate that for you rather than SSH into one machine one at a time just create a pain for each SSH into all of those activate synchronize mode by sending prefix and then y for yes that's just what I decided to set it to in the config file anyway you could change that if you'd like but once you do that it activates synchronized mode and the command that you're typing is being typed into every single pane to deactivate it you just send that same keyboard shortcut again so prefix why it tells me that synchronized mode has been toggled and now it's disabled I'm only typing in the one terminal window now but there's another really cool tweak that I want to show you and this will be the last tweak that I'm going to give you in today's video so what I'll do is just disconnect from this server right here I want to work with the local one so I'll open up the file and actually I think I already have that open and I did here it is anyway let's add some additional configuration here and I'll just paste it in again this is going to be in the official blog post for this video in fact I'll have more customizations than just these so you'll definitely want to check out that blog post there's going to be plenty more customizations where these came from anyway I'll paste in the most recent one and this has to do with theming now theming in tmux can get very complicated and it's not something that I'm going to cover in depth but what you could do is just find a configuration that looks good enough a lot of people out there will share their configurations I mean I'm even sharing mine with you guys as well and you can just tweak it if you don't like some of my colors you could just simply change them but what I'll do is save the file and I'll go ahead and reload tmux let's see what happens and look how much that's changed that's incredible on the bottom for example we have all of the windows in the center I just happen to like that better rather than having everything start at the left it starts in the middle that's just how I like it next to the host name here this is my footage PC I have Emoji yes you can add Emoji that's totally fine I have an emoji for a laptop even though this is not a laptop we're not going to go there I just thought it'd be cool so I added that in there on the right hand side I have an emoji of a clock next to the time which makes sense to me now what this customization will also do is color the current tab in blue so as I hold down shift and press the left Arrow or the right arrow we can see that the blue Highlight here is changing that helps me understand which window I'm currently attached to but that's not all if you check out the configuration the full configuration it's going to add another feature to this if you use the configuration as I have it it's going to change the font color of the title of the window there at the bottom to White if something changes that way if you're running a command in another window then you don't have to keep checking it you'll know that something happens when the font color changes that's just another thing that makes it all that much better again just check out the configuration file that I have linked Down Below in the blog post and you can steal my configuration I don't mind at all you can modify it do whatever you want with it and if you do something cool let me know in the comments down below what customization you have made but there's going to be a few more nuggets in that configuration that will be provided so definitely check it out now before I close out this video and also this series there's one more thing that I want to cover that I almost forgot to include when it comes to customizing tmux a config file is not the only way to do it now of course it's probably the easiest way to maintain a configuration but what if you want to do something like a one-off change and you don't want to create a config file well we can also set each option one by one manually by typing them into what's known as command mode within tmux itself now I'm not going to dive in super deep into this mode but I do want to give you a basic summary and make sure you're aware that it exists and of course what it does so let's activate command mode and enter a command so I'll send the prefix and then I'll type a colon now as you can see the bottom completely changed there's a cursor down there now and it almost looks like it wants us to type something well it does this is command mode now before I show you the First Command what I'm going to do is just set up a split you'll see why in just a moment so nothing different than what we've done so far we have our split and then I also have Mouse mode enabled that's something that we set in the config file so no surprise there but anyway I'll send prefix colon and let's type a command what I'm going to do is type set Dash G and then Mouse and what I'm going to do is turn that off and now I'm no longer able to use my mouse to resize this pane right here as you can see I can recall a previous command in command mode by going to command mode and then pressing the up Arrow and what I'll do is simply turn mouse mode back on again and now I can use my mouse within tmux yet again now even though tmux does feature command mode I think for the most part the config file is the best way to do it command mode is great for one-off changes like you've just seen especially if maybe Mouse mode is getting in the way of something in that case you could simply turn it off but I still like to include all of my configuration within the config file since that's a well more centralized place to store all of my settings anyway but from here the underpinnings of the command structure within tmux gets very complicated perhaps overly so but unless you want to dive deeper into tmux then the majority of those who use it every day I think this should be enough knowledge without overwhelming anyone the basic idea is that you can enter command mode by sending the prefix followed by typing a colon and that'll help you customize the behavior of tmux by entering commands one by one another thing I like about command mode that I find very useful is you could use it to preview changes that you would normally include in your config file but you could type the individual commands here to find out what the configuration option does before you put it in your config file giving you a basic preview but all in all you now know what command mode is if you want to read even more about command mode I'll leave some links in the description down below that'll give you all the information you could ever want about this mode but I think for now at this point in the series if you've been following along with me you should have all the knowledge that you need to use tmux on a day-to-day basis thank you and there you go we've reached the end of the tmux series here on learn Linux TV I had a ton of fun producing this series for you guys and I would really appreciate it if you shared this with someone else you could share it on LinkedIn Facebook Twitter wherever you think someone might benefit from tmux knowledge you can even share it with your cat if you wanted to I don't judge if your cat is able to use team-ups then your cat probably should use tmux anyway there's definitely more where this came from more awesome Linux related content that's coming very soon to this channel so make sure you're subscribed to learn Linux TV for the latest in Linux and I will see you in the next video foreign [Music] [Music] foreign [Music]
Info
Channel: Learn Linux TV
Views: 16,115
Rating: undefined out of 5
Keywords: Linux, gnu/linux, LearnLinuxTV, Learn Linux TV, LearnLinux.TV, Learn Linux, Linux Training, Linux Tutorials, tmux, tmux tutorial, tmux guide, getting started with tmux, learn tmux, tmux tutorial for beginners, tmux tutorial linux, tmux tutorial youtube, tmux tutorial ubuntu, tmux basics, terminal (software), tmux for beginners, terminal multiplexer, tmux configuration, tmux config, tmux settings, tmux plugins
Id: -f9rz7joEOA
Channel Id: undefined
Length: 25min 50sec (1550 seconds)
Published: Sat Aug 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.