0%

MacOS Keyboard Settings and Shortcuts for Coding

Some of the default keyboard settings and shortcuts on macOS simply don’t work for me as a software developer. As soon as I get my hands on a new mac, I change some keyboard settings and shortcuts for general text editing, window management, iTerm2 and some other stuff. I’m going to go over everything I do step by step in this post. I’m sure you’ll find at least some of these tips & tricks pretty useful.

Keyboard Type

First of all, if you’re using an external keyboard, you should make sure that your keyboard is identified correctly. Usually you don’t have to worry about this, but recently my keyboard was identified incorrectly for some reason while I was setting up macOS for the first time on my new Mac Mini.

You can check the identified keyboard type from System Preferences > KeyboardInput Sources

If you find out that it’s incorrect, go to System Preferences > KeyboardKeyboard and select Change Keyboard Type

For me, it turns out my keyboard was identified as ANSI while it’s actually ISO, so I had to change it:

iTerm2 Natural Text Editing

Natural text editing shortcuts such as the ones below do not work by default on iTerm2:

  • ⌥→ (next word)
  • ⌥← (previous word)
  • ⌃→ (end of line)
  • ⌃← (start of line)

You have to set the preset as “Natural Text Editing“ in order to fix this:

iTerm2 > PreferencesProfiles[Profile Name] > KeysPresets

iTerm2 Tab/Pane Switching

iTerm2 lets you create multiple tabs, and you can even split a tab into multiple panes.

  • ⌘T creates a new tab
  • ⌘D creates a new pane by splitting the existing tab horizontally
  • ⇧⌘D creates a new pane by splitting the existing tab vertically

These default shortcuts for creating tabs & panes are pretty nice. However, I don’t like the default shortcuts for switching between tabs/panes. That’s why I override them like this:

iTerm2 > PreferencesKeysKey Bindings

Switching Between Windows of the Same App

⌘Tab is pretty useful for switching between different apps. What if you need to switch between windows of the same app? Sometimes, I have multiple iTerm2 windows or multiple VSCode windows open at the same time and I want to be able to quickly switch between those. Here’s how you can (re)assign a shortcut for that:

System Preferences > KeyboardShortcuts > Keyboard > Move focus to next window

Window Organizer: Spectacle

Spectacle is a free app that lets you organize and resize your windows using keyboard shortcuts:

It’s no longer actively maintained, but I’ve been using it for a couple of years and I’ve had zero issues so far. It’s quite simple, and the default shortcuts are pretty good.

Key Repeat and Delay

I use Vim for text editing, which means I don’t use my mouse to navigate in the text editor. That’s why I frequently need to press and hold some keys for scrolling up/down/left/right in the editor.

By default, key repeat is too slow and the delay until repeat is too long to do that fluidly. I adjust the settings like this, but you should experiment with each option on your favorite text editor and see what works for you the best:

System Preferences > KeyboardKeyboard

VSCodeVim Extension

You should only read this section if you use both VSCode and the VSCodeVim extension.

Pressing and holding the arrow keys (, , , ) lets you fluidly navigate between rows (lines) and columns (characters) in the editor by default.

Unfortunately, that’s not the case for Vim equivalents (h, l, k, j). For instance, even if you press and hold the j key, it only advances to the next line and it gets stuck there by default. You have to run one of the following commands after installing the VSCodeVim extension to have the same fluid behavior, as pointed out in the GitHub page of the extension:

1
2
3
4
5
6
7
8
9
10
11
# For VS Code
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

# For VS Code Insider
defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false

# For VS Codium
defaults write com.visualstudio.code.oss ApplePressAndHoldEnabled -bool false

# If necessary, reset global default
defaults delete -g ApplePressAndHoldEnabled

A Handy Shortcut: Control + Space

I think ⌃Space is a very handy key combination and should be assigned to a frequently used shortcut. However, it’s assigned to another shortcut by default, so it needs to be unassigned first.

My command-line shell preference is zsh and one of my favorite zsh plugins is zsh-autosuggestions. It allows you to define a custom hotkey to accept the current suggestion. For me, ⌃Space fits perfectly into this use case.

Bonus: Font Smoothing

I know that this isn’t related to keyboard settings or shortcuts, but I still want to mention it because I think it’s important.

I don’t know about your experience, but the default font smoothing is too much for me. What’s worse is, macOS doesn’t let you change this setting easily from system preferences anymore. You have to actually open the terminal and run this command:

1
2
# 0, 1, 2, or 3
defaults -currentHost write -globalDomain AppleFontSmoothing -int 1

Setting it to 1 works best for me. I suggest you to experiment with each option (0 is lowest, 3 is highest) and see whichever feels best. Keep in mind that in order to see the effects, you have to logout & login back every time you change the setting.


Feel free to leave a comment on Twitter if you have some other tips & tricks that haven’t been covered in this article. I’d love to hear them!

Welcome to my other publishing channels