What is the Meta Key ?
The Meta Key (denoted as M or Meta) is a modifier key which mean it temporarily modify the normal action of another key when pressed together. Common modifier keys are shift, alt, or control. The meta key was a special modifier key marked with a solid diamond ◆. Bash uses some meta keys combination for some advanced control that can quickly improve your velocity and productivity on the shell.
Unfortunately, keyboards without a meta key, and on macOS, this mean that meta key is replaced by the esc key which is not convenient at all and often more clunky than helpful. Though, you can have your macOS Terminal configured to use the option key as a meta key.
Why using Option as Meta Key?
With the meta key properly set for your Terminal, you can quickly improve your shell productivity by using some of the following sequences; assuming that you use the default bash keybindings which is based of emacs.
|M+f||Move forward one word (vs per character)|
|M+b||Move backward one word (vs per character)|
|M+u||Uppercase a full word, starting at cursor|
|M+ul||Lowercase a full word, starting at cursor|
|M+d||Delete word forward from cursorv|
|M+delete||Delete word backward from cursor|
|M+s||Swap current word with previous word|
How to Configure Terminal to Use Option as Meta Key?
You can programmtically configure your Terminal using
defaults. If you are not familiar with this command line tool on macOS, check the post
How To Change Preferences from the Command Line on macOS?.
The domain for the Terminal app is
com.apple.Terminal. You will need to look for your default Window Setting with the key
Default Window Settings. Then, based of this, look at the corresponding nested dictionary inside the dictionnary
Window Settings and set the key
Alternatively, instead of using
defaults in the command line, you can simply go to the
Preferences... (or type ⌘+,). Then,
Keyboard and check the box
Use Option as Meta key. Though, this wouldn’t be as fun.