Check out a free preview of the full Developer Productivity course

The "Cheat Sheet" Lesson is part of the full, Developer Productivity course featured in this preview video. Here's what you'd learn in this lesson:

ThePrimeagen demonstrates using the program Cheat Sheet to search for answers to programming questions such as core utilities, language specifics, and even TL/DR on learning a language without having to open a browser. How to copy and paste from the terminal and a student's question regarding why the keybinds are not just set in tmux are also discussed in this segment.


Transcript from the "Cheat Sheet" Lesson

>> I wanna take it to the next level. I wanna make this even more awesome, right? We just made something that was sort of awesome. I wanna make it awesomer. I wanna make it max level awesome. I wanna make it level 9000 awesome. So first before we say what the problem is, I wanna say something that we all face as a developer.

I think you can kind of guess where I'm going with this one. But here's a couple questions I have for you. You probably know at least two of these answers. Perhaps you're just really adept in these three languages that I mentioned here. And so you know all the answers.

But these are just questions we have typically. Developers, we all go, okay, how do you tokenize a string in C? I know it's not .split, because C is not simple. C is like any other programming language, just hard. That's kind of my motto. I think that should be its motto too.

I think C would be really beneficial if it just was like, C it's hard and then that would be really good. So these questions obviously are questions we ask ourselves all the time. If we just google them once or twice and then for the most part, you know how to do it.

And then you can kind of just remember it from there on out. But what if we just don't even need to open up a browser. Right now I hate going in here and going, how to tokenize string in C? And then go here and then read stack overflow.

And then some guy's gonna be like, well actually this is the best way. What about this one this way? Then some guy down here has like negative four, look at that, negative one. Someone's always wrong on stack overflow. Someone's always right on stack overflow. It's just not a great experience to me.

I'm like, whatever, I don't wanna deal with it. I want something that's a little bit easier. I just want the answer. Tell me how do I tokenize a string? And so for me, I technically can do that. I can jump in here and I can go C and I can go tokenize string.

And then what it's gonna do is it's gonna come back and it's gonna tell me, this is how you tokenize a string. So I can now take it in C and boom, I am now using this in C. That's fantastic. When I'm done, I press Ctrl+C, close it.

Boom, we're back to right where we just were. That is fantastic, that is beautiful. And of course it uses that wonderful fuzzy finder that we all just got done using, so we already know how to solve half this problem. So the program that I'm using is called Cheat Sheet.

It is beautiful. I use it more and more and it's one of the best ever. It also has TLDR already kind of integrated with it. If you don't know what TLDR is, TLDR you can ask it things like, hey TLDR find. It's like, hey, here's basically how you use find.

You're like, okay, I didn't know that. That's awesome. TLDR sed, here's basically how you use sed. It'll give you some basic kind of hints to use it and you can use that as a springboard to learn more about sed. So let's try a couple of these. Let's try this right now.

Let's go like this, curl So if you don't know, when you use find you can actually even exact something over the find. Because what ends up happening here is that if you were to do this exact same thing right here where instead of doing exec, to ls dash lh, you instead typed it out.

It actually is a little bit less efficient because it has to do this whole communication thing. There's a bunch of people writing about how it can speed things up like a huge percentage by using find, doing the execution as opposed to typing everything out. And so it's actually something that's pretty useful.

At least that's what I've read. I haven't ever ran into a spot where I've needed find to be ultra performant cuz I'm always doing very, very simple things such as just searching for a few items within a small confined area. And of course, find is also rewritten in rust using Fd, so if you ever want to do something better, which is because it's written in rust, it's better, faster, smoother and safer, you can use Fd.

I don't currently use Fd but I hear it's safe and it's fast and it's awesome and I heard you should use it because it's written in rust. All right, so we can curl, hey, how to use splice? That's how you use splice. Hey, you know what I always forget?

What's how do you do a Java scripting or type script enum? Here's how you do TypeScript/enum. Well, how do you do TypeScript/enum with a string? Well, here's all the different ways you can do a TypeScript/enum with a string. Look at that, here's how you do an enum. Here's how you do it in this version, yadi, yada, a lot of things too fit in there.

So pretty awesome. I really do like using Cheat Sheet, it has a lot of answers. Obviously if you kind of, there's a point where when you give it too much information, it just responds with, I don't know. I didn't really do it right there, but you'll get the I don't know from time to time.

And so there's two things I did there. Notice that I did this style and this style. Whenever you have a curl util, you can ask for kind of how to use one of its basic items. Cheat sheet slash find tilde exec or if you have like a language thing, you do cheat sheet slash javascript slash plus delimited string.

So this just allows you to splice plus array so meaning, how do you splice an array? Awesome, so it's kind of like you already have Google skills, you pretty much already have cheat sheets skills. And it's pretty straightforward. And you could also good fun kind of side fact here is you can also go curl cheat sheet and you can go golang and then you can just do learn.

And this will give you everything you pretty much need to know about golang. It's gonna I shouldn't here, let me pipe it into less less, just gives you a little bit out of time. It's gonna go like, hey here's a program beyond hello. So here's Hello World beyond hello and then it's gonna go through show you all the summing, show you how to multiply learn types, blah blah blah.

Here's all everything you need to know about types. And it's gonna go on and on, you get it returned, all that, really, really nice. So if you're already pretty good at programming and you just want to get a quick understanding of how a different language works, really awesome little program just to go, okay, I generally get how golang does a lot of syntax.

Now it's time for me to learn it by doing it. And if I need to learn something, I'll just do something really, really quick. So learn is pretty cool. So, this is what somebody already asked. Did you just copy and paste from the terminal? Yes, I did. So usability tip, tmux prefix, open bracket goes into vi mode.

And if you happen to have these inside your tmuxrc, which remember your tmuxrc is in your home directory. I'll kind of go over this a little bit more, just a touch more in the next section or two. It will allow you to be able to copy. And what effectively it's saying is that, hey, when you're in copy mode in vi, when you do a copy, I want you to send it to a program, and I have xclip.

If you're on Mac OS X, you're gonna have pbcopy. So you're gonna have to put in the correct copying command, and then, it will send it to your clipboard. So when I do this and I go prefix open bracket, you'll notice that I can walk around in here.

And then, I can just use Shift+V and it will highlight a line, go down, down down, use y so it's kind of like vim. And now I've just highlighted those lines, yanked it to my system clipboard, and then I can just paste it all I want. And so in conjunction with cheat sheet and a little cotton taste thing, it's very, very easy to just grab the information you want and yank it around.

It's pretty cool. I genuinely think it's a super fun feature. There's also a lot of other tmux plugins you can use, which will help you grab a UIDs out of your terminal, help you do this, help you to do that. It's pretty slick. There's a lot of cool stuff you can do with tmux that I'm not even talking about, or I really even use.

So let's do it, let's build the next script. I feel like this is good. Wait, what's the next one? Let's see Hon, we have the knowledge this time. Yeah, we can just build it. Let's do a little drawing. That's drawing has gone just way too complicated. So complicated no one can even use it.

But let's do this. We have Cheat Sheet, so we know, my goodness, look at how beautiful my handwriting is, cheat sheet. Now that is beautiful. So we have cheat sheet, we know how it works effectively. We have a language. We have a language we can put in here.

Or a corel, a core util and then here we do slash and then we do some sort of plus dlm string. And this one we do tilde. And then we can do one of the facets, one of the parts. I don't know what you call this thing, query parts.

Whatever you wanna call it. There we go. So those are kind of two URLs we need to generate. That should be pretty easy. And then we can programmatically figure out, do we want to send languages or core utils out? So we could select from some sort of list.

From those two lists, we can know if it's a language or a core util. From there, we can then ask for a query. And from there, we can send all that information out. So this should actually be pretty straightforward to be able to build this part, the only thing we need after that is to be able to build the tmux part out.

We're gonna want to actually create this command and execute it in say a new window with tmux. So I think that shouldn't be too hard cuz we do know how to create a new window. We know how to change this directory, give it a name and how to execute a command.

So we should kind of know roughly everything we need to know to build this. So let's kind of build this right now. So I'm gonna go back to temp, why do I do my key binds for that previous script in ZSH and vim and not just tmux? It makes a lot of sense, why should I just do Ctrl+A F, boom, I'm running, it's fantastic here?

I'm gonna create the file first. We're gonna save the file. So we have that Cheat Sheet file that we're about to create all ready to rock. So why don't I do them? Well, here's the primary reason, I'm gonna detach from tmux. I am not in tmux right now, whenever I start up a new terminal, I start up a new terminal.

Am in tmux right now? No, I'm not in tmux, I'm not always in tmux at certain points, so if I can just press Ctrl+F and give myself the appearance of this fast navigation. Go to the temp folder that I wanted to. Now, we're back to where it works.

Now that I'm in vim, Ctrl+F won't work because it's not with ZSH. So if I just press Ctrl+F here, it uses a new window, creation commands. So that's why it's right here to create a new window so it still gives me the appearance of looking identical. So when I choose something else, it will go to that place.

And when I hop back, I'm still back in vim, and that previous window is gone. Those are the two points of interaction that I really do. And so I feel like that's sufficient. I almost never open up vim outside of tmux. But theoretically, I should probably do a little bit better.

I mean, I could make it even better, where I don't even have to be in tmux for Vim. I could just have like a, hey, are we in tmux check? Then do this, else, do that. Create a new tmux session with all this name stuff all the way through and run this command.

We could do it that way. I just didn't wanna do the tmux one cuz, hey, I don't wanna press prefix, I don't know why. I don't know why I just don't wanna press prefix and two, I just wanted it to feel the same when I'm in Vim or in the terminal.

So that's kinda why I chose what I chose, personal decision dump. So I have kind of obtuse reasons for the reasons why I choose things. They're kind of just like I just get super stoked about the way I like things and then sometimes I look back like a year later and I go, I am an idiot.

I guess, it's just part of things. I just get excited.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now