The Super-Secret Mac Keyboard Shortcuts Almost No One Knows About

Beyond the menu bar keyboard shortcuts and the ones you can add in System Preferences, there are a set of keyboard shortcuts called KeyBindings that you can use when writing. These customizable keyboard commands can be used to move around in text, manipuate selections and even insert frequently-used words and phrases.
You can also watch this video at YouTube.
Watch more videos about related subjects: Keyboard Shortcuts (82 videos).

Video Transcript

Hi, this is Gary with MacMost.com. Let me show you some super secret keyboard shortcuts. I'm not talking about the keyboard shortcuts you find in the Menu Bar. I'm not talking about the custom ones that you create in System Preferences. I'm talking about something different. You're going to want to see this!
MacMost is brought to you thanks to a great group of more than 1000 supporters. Go to MacMost.com/patreon. There you could read more about the Patreon Campaign. Join us and get exclusive content and course discounts.
Now you probably already know that you could access keyboard shortcuts for any Menu Bar command that there is. You could see them right in the Menu Bar. You can also go into System Preferences and create your own keyboard shortcuts. But there's another very hidden set of keyboard shortcuts that you can use called Key Bindings. There are a bunch of default Key Bindings that aren't that useful. But you can create your own custom Key Bindings and those can be really powerful. 
Key Bindings are mostly useful when you're typing. They are not things that you use to access functionality in apps. They are more for when you're typing in apps like TextEdit, Pages, the Mail app, a form in Safari. Just about anything that you type in you can use KeyBindings as shortcuts. So the built-in ones really aren't that useful. But I want to start by just showing you those. So, for instance, here I am in TextEdit and I can use Control F to go forward and Control B to go backwards. That's Control not command. Now these aren't that useful because the arrow keys will do these for you. There's some other ones like Control A to go to the beginning of a paragraph, Control E to go to the end, Control N will go down a line, Control P will go up. You can delete characters with Control D or in the other direction Control H. Control O will insert a line. If you have something selected Control L will jump to that selection and highlight. That's not that useful here but if you had a long document and your selection was somewhere you scrolled away from Control L will get you back there quick. Some other ones are Control K to delete to the end of the line and the very weird one Control T to swap two characters. There are a few others but you get the idea. For the most part they are not super useful which is probably why you haven't heard of them before. 
But you can create your own Key Bindings and those can be extremely powerful. So the way to create your own is you have to create a special file. So to do that I need to first create a special folder in the Library folder. So in the Finder here I'm going to create a New Finder Window. Then you Go, hold the Option key down, you can go to the Library. Then I'm going to look for the folder called Keybindings. Chances are you don't see it because it's not there. You need to create it yourself. So you're going to go and create a new folder and need to call this folder exactly Keybindings like that. Then in this folder we need to create a text file. I'm going to go back to TextEdit, create a New Document, make sure that document is set to plain text. Now it's a plain text document. Go to Save it. To Save it into the folder the easy way to do it is to drag and drop the folder into the Save dialogue that jumps right there. So make sure you saving it to Library, Keybindings. Then you need to name this exactly. DefaultKeyBinding. Then the extension should be dict exactly like that. Make sure you uncheck the use .txt there. Because you don't want it to be .dict.txt. So I'm going to Save this and now I've got this file here. I can look in KeyBindings and check to make sure it's there. I going to actually use Command i on it to make sure that the actual name of this file is KeyBinding.dict. No .txt afterwards and that I haven't added any extra spaces. It's exactly like this. This is tricky because the folder name is Keybindings with a lower case b and this file is DefaultKeyBinding with a capital B and no s. So you've got to make sure you got everything right. 
Now I'll close this and I've got the file open here and I can create a Keybinding. I'm going to start with a curly bracket. I'm going to go to a new line and then Tab. That's all cosmetic there to make it look nice and neat. But now in quotes I want to put the Keybinding which is going to be Control and then uppercase U. I'm going to use Shift 6 to have a caret that represents the Control key and then Shift U for uppercase U. So this is actually Control Shift U. If I did a lowercase u there it would just be Control u. Then I'm going to do equals and then in parentheses the command that I'm going to issue which in this case is uppercaseWord. We'll learn about more commands in a minute. You put a colon after the command. That's just how it's done. Close the parentheses and put a semi-colon there and now on a new line close with curly bracket. It's got to be exactly this. You can't forget the quotes. You can't forget to have both ends of the parentheses or the colon or the semi-colon. If anything is different, if you spell this differently or put a space there or something it's not going to work. So you have to be precise. 
Now I'm going to save this. Now when you save a new keybinding that apps running don't know anything about it until you quit them and relaunch. That's very important. I know I'm going to get questions with people saying it's not working for me and the problem comes down to they haven't simply relaunched the apps that they are using. So in this case I going to test in TextEdit. So I want to Quit TextEdit and relaunch it. Now this keybinding should make it so that if I have my cursor in a word and I use Control Shift and U it makes it uppercase. But Undo there and you can see it even works if I select several words. If I have a selection like that and do it it's going to make it uppercase for all of that. So there's something handy. It's not particularly special because I could always have gone to Edit and then Transformations and then make uppercase. It does the same thing. It's actually using the same function in the background to do those things.  But now I just have a quick keyboard shortcut to do it. I could add more here really easily. Just go to a new line and let's do Control but also Option which is Shift and then a tilde, that's the key above the Tab key on US keyboards, u. So no shift needed because that's a lowercase u. Then LowercaseWord like that. Save. I have to Quit TextEdit, relaunch it again, and now I can put my cursor in a word there. Do Control Shift U and Control Option u. You've got the Control key, the Option key, you can also use the @ symbol or Command and some documentation for this shows the dollar sign for Shift. But I find that doesn't work. You simply have to use the uppercase letter for shift. 
Now, of course, these may not be that useful since there are already ways to do these in the Menu and you then you can use keyboard shortcuts for those. But the parentheses here are masking a really important thing. You can have several commands attached to one key. So here is another one. In this case I'm going to use Control and the number one on the keyboard. I'm going to issue a bunch of commands here separated by commas. So the first one is move to beginning of paragraph and then move WordRight, and do that again. So move two words forward. Then a regular move right which will move forward one character. Then move right and modify selection. So that's going to select one character to the right. Do that three times. So what this will do is it will go to the beginning of the line, move forward two words plus one space and then select the next three characters. Let's Save. Then Quit, relaunch TextEdit and give it a try. I'm going to put the cursor way over here and I'm going to use Control 1 and you can see it did exactly that. It gave me the first three characters of the third word. Now whether you need to do that specifically or some other modification of this you can use beginning or end. You can move right or left by word or just one character at a time. You can move right or left and modify selection to select. So if there is some specific task that you need to perform on a bunch of text data you can create shortcuts like this to make it easy instead of having to do all these different things or fumble around with the cursor to select things. You can setup a series of commands like this and assign it to a single keyboard shortcut.
Here's another one. Here I've set Control Shift T to select a paragraph, so the entire paragraph that's there, and use capitalizeWord. So it's going to make it titlecase. Every word will have a capital letter at the beginning. But notice at the beginning I have it setMark and then swapwithMark. What this does is it remembers the selection and then here it restores the selection. So let's Save this, Quit, relaunch TextEdit and let's say I put the cursor right here in the middle of the word fox and I use Control Shift T. You could see it did all of those things. It remembered where the cursor was. Then it selected the entire paragraph. Made it all start with capital letters and then restored the selection right to that point. You could even keep it simple with two commands just like this. So in this case Option 1 is going to just set the mark. Option 2 is going to restore the mark and for good measure it's going to center selection in visible area. Remember that Control L that I showed you in the beginning. That's what that does. So let's Save this. Quit. Run again and let's add a bunch of extra lines here. So there's a bunch of extra lines. I could go Select this Word. Do Option 1. I can go here later in the document and do Option 2 and it will reselect that word and jump to it.
Here's another one. Control and then the left parenthesis which is Shift 9 on US keyboards. That's going to remember the selection. Move backward one character. So it will go to the beginning of the selection. Then it's going to insert some text. What ext is it going to insert? Well, that's in the next command. Notice this command here is insert text. The next command is the text to insert. So a left parenthesis. Then it's going to restore the selection again. Then move forward. Go to the end of the selection. Move forward one extra one. Why? Because the selection we remembered didn't have this character we inserted. So it's got to get to the end with one more character. Then it's going to insert text. A right parenthesis. Let's Save. Quit and bring it back and now I can select some text and then use Control Shift 9 and the result is it surrounds it in parentheses using this series of commands. 
But wait a minute, you say! This insert text is really interesting. Can we use this just by itself? Sure. So let's go and just have Control 2 just be an insert text and have a bunch of text inserts. Save that. Quit. Relaunch. You can go to a new line here and Control 2 inserts that text. This is kind of like a text replacement but you don't actually have to type the text to replace. Instead of having to type a word and hit space or return or something and then have the text replaced just one keyboard shortcut inserts this text. So it's a quicker way to insert text that text replacements which will be great except that how many keys are there on the keyboard. I mean you can use Control 1, Control 2, all the way to Control zero. Maybe a few other things. Eventually you're going to run into conflicts with other keyboard shortcuts and you're going to have to remember all that stuff. But the cool thing about keybindings is that you can nest them. Let me insert this here. You can see I'm going to use Control and lowercase t. So just Control t equals and then put another curly bracket and then have a set of keybindings that actually have to happen after this. So in order for these to work, these little insert text commands, you have to do Control t followed by another key. So I've got three different ones here. Let's Save this. Quit. Relaunch. Now on a new line I can do Control t and then a, Control t b, Control t c. That really expands the amount of these things that you can have. 
I'm going to show you one more one. In addition to all those modified keys you can use pound or the hash symbol and that indicates the numeric keypad. If you have a numeric keypad on an extended keyboard like I do you can actually use that and have a single key press to do one of these. So, for instance, I can have it do an insert text like that. All I'm going to do is hit the 1 on my numeric keypad. So let's try that one out. Just pressing 1 on the numeric keypad does what I need. So I can have nine plus of those just using my numeric keypad for these little text insertions or any of these shortcut commands. 
Now to show you that this doesn't just work in TextEdit let's try some different apps. For instance here we are in Pages. Let me use that Control 2 and you can see it inserts there in Pages. I can select this and use Control Shift U and you could see that it does the uppercase. So Pages works great. The Mail app is somewhere you're probably going to want to use this as well. So Control 2 you can see that works. I can select all of it. Control Shift U. That works. In the Messages app I can use it. Control 2 inserts that in there. It's an easy way to paste in quick messages that you use often. It even works in Numbers. You would expect it to work while you're typing inside of a cell like that. But I was surprised to find all you need to do is select a cell and then you could actually use it like that and it knows to insert text. Even in Safari inside of a text box there. So here we go. Like that. Select it all. Control Shift U. These all work in there. 
Remember you have to relaunch apps after you change keybindings for this to work. It's very easy to forget that. You test it out in TextEdit find that it works great. Then try it in Safari and find that it doesn't work at all. That's because you had Safari running the whole time. You need to Quit Safari, Relaunch it, and then Safari knows about the changes. So there a lot or pitfalls here. You've got to make sure you create the right file with exactly the right file name. Put it in the right spot with the right folder name. You've got to make sure that you think like a programmer here and make sure you have everything perfect. Make sure you don't forget any quotes, any parentheses, the colons, the commas, the semi-colon at the end. Anything that you miss is going to make it so things don't work. So you've got to be really careful with it. 
Then you also have to worry about conflicts. If you're using a keyboard shortcut that already exists in that app, it's not going to work. You want to make sure you use a keyboard shortcut that doesn't do anything else. So if something isn't working try another keyboard shortcut because that app may have a conflict. Remember apps have different keyboard shortcuts. So something that works in TextEdit may not work in Pages because Pages already has something assigned to that keyboard shortcut. And it may or may not work in some apps. For instance when I tried this in Microsoft Word I was able to get some text insertions working, like ones with the numeric keypad. But other ones either conflicted with existing keyboard shortcuts or Word was blocking them somehow. So if you're using Microsoft Word you got to kind of use their own tools for things. You can't use keybindings. Terminal also has its own thing going on. If you try to use these in Terminal they won't necessarily work. But for just about everything else it seemed to work just fine. 
Now you're probably also interested in the commands. How did I know that uppercase word worked and move word right worked, insert text and all those. Where did those come from. Is there a list? There's really not a great list anywhere. Some Apple documentation or developer stuff has some of these in there. But not all of them work in keybindings. Here's a bunch of different places you can go to get a better sense of what's available. I'm going to have all these links in the post for this at MacMost.com. So, for instance, here somebody posted some useful information that includes the modifiers. Although note that I find the dollar sign shift doesn't work. Here are some key codes for things like arrow keys and the Home key and things like that. So you can use those in KeyBindings, and some examples of how to use those. Here's somebody that actually created a DefaultKeyBinding.dict file that has a lot of useful things in it. You can use this to search through it and get ideas for other commands that are available like that one or this one or Cut and Copy. All of those. So looking through other people's keybindings that they have posted can help you find commands. There's also a series of pages here that is pretty old but seems like most stuff still work. Going into some detail about these keybindings there's a handy list here of a lot of the different commands. Another handy list here that shows you how existing keys are already using these keybindings. So you could actually use something that's already in use like move left to the left arrow and that's how you can add that command to your own keybinding. 
So look through these pages if you're really interested in digging deep and creating your own keybindings that do powerful things. Hope you found this useful. Thanks for watching.

Some links:
https://ss64.com/osx/syntax-keybindings.html
https://github.com/ttscoff/KeyBindings
https://www.hcs.harvard.edu/~jrus/site/cocoa-text.html
http://www.hcs.harvard.edu/~jrus/Site/selectors.html
https://www.hcs.harvard.edu/~jrus/Site/system-bindings.html

Comments: 10 Comments

    Milo
    4 years ago

    Thank you Gary! That took some work but I have eliminated one tedious bit of typing that I need every day.

    Patricio
    4 years ago

    Very good advice on how to use secret shortcuts. I needed it to save time.
    Thank you Gary

    Henry
    4 years ago

    Hi! Great stuff! Was really exited for this but unfortunately I can't get it to work. My guess is that the commands "insertText" for example, has different names in my Macs system, since I am Norwegian. So the question is, do you (or anyone else) have any clue to where I could find a list of these commands BUT in Norwegian. I tried a lot to swap out my self, but since I´m honestly not sure if this is the problem, or if I made another mistake (I don't think so), I just have so much patience :/

    4 years ago

    Henry: I would assume that the commands are always "insertText" and such, and don't change depending on the language. I would continue to try to look at other causes for the issues. Maybe try one of the very simple examples I show.

    Razvan Mihai
    4 years ago

    Thank you, Gary, for the very well-explained tutorial. I wondered if there are any key binding to change the color of a word or a selection in much the same way as you showed how to change upper/lower case words. I did find something on the topic, but the documentation seems old, and there are no implementation examples.

    https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html

      4 years ago

      Razvan: Doesn't apply here, unfortunately. That's a page for app developers. The part about text color is actually a separate section on that page from the part about key bindings. You can't change the color because key bindings don't affect styling. That would be dependent on the app and how its menus are set up.

    Razvan Mihai
    4 years ago

    Gary: Thanks a lot. I was hoping key binding is the answer to changing the color of a piece of the highlighted text in the Notes app with a simple shortcut instead of manually picking the color with the mouse after pressing Command-Shift-C. I was able to find apple scripts that do this for TextEdit and Pages but couldn't get them to work for Notes, which seems to require more elaborate scripting. https://www.macosxautomation.com/applescript/notes/04.html

    4 years ago

    Razvan: Using Command+Shift+C seems pretty fast to me. I don't know if you will cut that time any more with keyboard shortcut to an Automator action. At best you can save one click, but it may take hours or days to construct something in Automator to do this (depending on your skill level) if it is even possible.

    MacSakki
    3 years ago

    What do I need to use to change a paragraph into a title? “capitaliseWord” does not do the trick.

    3 years ago

    MacSakki: I wouldn't use Key Bindings for that. Use Edit, Transformations in almost any app.

Comments are closed for this post.