The most common shortcuts for code editing | OSX

Most Common Text Editor Hot Keys For Programmers

Here are a list of hot keys that work the most universally as possible for text editing. There are so many hot keys and yet so little time. Which hot keys should you learn? If you work in the command line and on a Macintosh (OSX) this is the right chart for you. The first chart goes over the hot keys that are most ubiquitous. These have been selected for their wide support. If you are going to learn only a few these are the ones to learn. Then below, (as a plus) I get into specific common hot keys that I use in different applications.

I use the escape key (esc) for my meta key. You may not be set up to use the escape key as the meta key so keep that in mind. What is the meta key? This is normally escape but you can configure iterm to bind another key to meta if you want. See “The Meta Key" bellow if you want to know more.

What are each of the items in the header in the chart below?
Emacs is an old text editor from Unix many of the hotkeys from the editor were adopted at early stages into the OSX text fields and text editors. Most legacy Emacs hotkeys can be used for editing text in OSX. Atom is a text editor from git hub that is a lot like sublime text. Readline is the line editor used when you are working at the terminal.

Universalish Hot Keys
Shortcuts shared across common text editors
When I say universal(ish) I mean that these are hot keys that are available in most text editors that coders use but sometimes configurations have to be done in order to get them to work universally.

ctrl-a - go to beginning of line

ctrl-e - go to the end of the line

ctrl-f - move forward

ctrl-b - move backward

ctrl-p - move up

ctrl-n - move down

opt- - move forward a word
(maps opt+→ to esc+f)
opt- - move backward a word
(maps opt+← to esc+b)
ctrl+opt-f - move forward a word
ctrl+opt-b - move backward a word
ctrl-k - delete to the end of the line

option-backspace - delete word to left
(maps opt+←delete to ctrl+w)
(See “how to bind a key sequence to control" below)
option-delete - delete word to right
(maps opt+→delete to esc+d)


✓ - supported
🔧- works because of configuration (see below)
😲 - doesn’t work, minor exception

Other keys that interestingly share a few applications:

ctrl+w - delete word to the right

ctrl+u - delete everything to the left

If you are using a Mac and you are using the built in terminal I suggest downloading ITerm2 instead so that you can change command mappings to make the terminal easier with which to work.

The Meta Key

The meta key is just a place holder word for whatever key you want to bind to it. In ITerm you can bind the left option key or the right option key to the meta key if you like by going here:

How To Configure Shortcuts in ITerm2?

1.) Click : Menu -> Preferences...

2.) Click “Profiles" tab

3.) Click your profile or the default one

4.) Click the “Keys" sub tab

5.) Click the “+" plus sign next to “Load Preset…"

6.) Type your keyboard shortcut in the first field

7.) Choose either “Send Text", “Send Hex" (more on sending Hex in “How to bind a key sequence to the control key" below or “Send Escape Sequence". In this case we are using “Send Escape Sequence"

8.) In the last field choose characters that read line can interpret. (see references for about readline)
“^[" is the read line sequence for escape. This entry maps opt+→ to esc+f (may be alt+f in other terminals)
This effectively maps the emacs short cut to a read line shortcut.

How to bind a key sequence to the control key (ex: cntl+)

1.) Download “Key Codes" from the app store. Install it and open it.
2.) Hit the control+[some key] in this case I’ll use ctrl+w.

3.) The code in the red square is the code we want to send to the terminal
4.) Now map your key sequence using in iterm, preferences->Keys->+

5.) This will now map opt+←delete to ctrl+w in the terminal, but you can use it to map any key to another one.


Legacy Emacs Short Cuts:

Read Line Shortcuts: (Note: alt in this table is the meta key, which is usually esc)

ITerm Docs:

Application Specific Hot Keys I Like
Mostly this post is focused on universal hotkeys that you can use almost every where. But if you’re interested, here is a bonus. A lot of blog posts about hotkeys and workflows have a lot of key sequences that people don’t really use frequently. These are shortcuts that I use almost every day. If you’re looking for a few candidates to add to your skills look through the lists below.


ctrl+cmd-space - bring up the emoji browser.
(meta .. I know)
cmd+space - brings up the spot light search
( I use this to open applications mostly)
Don’t waste your with launch pad or the dock. Just search the application and hit enter.
cmd+tab - switch to a different open application
Don’t waste your time finding windows or using the dock.
hold down cmd
tab tab tab
then release
This will change to a different application shown in the application switcher.

Or to toggle between two applications.
then do some work in that application and then
cmd+tab release
to switch back to the previous application.
cmd+` - switch to a different window in the open application
One you are in an application you might want to cycle through the windows inside of that application. Don’t waste your time with the windows menu, just cmd hold and then press ` to cycle through.

Atom is an open source code editor with many useful plugins

ctrl-m - jump to reverse bracket
If you have something like the following:

if { /*some really long code*/ }

If you are at the closing curly bracket and want to jump to the opening curly bracket or vice versa, select the bracket and hit ctrl+m.
cmd+shft+\ - to display file in tree
If you have a file open but you want to see where it is in the project then hit cmd+shit+\ and the file will highlight on the file browser bar on the left.
cmd-l - to select a whole line

cmd-t - to fuzzy search for a file name in the project

cmd+f - to search current file’s text
type text in search field
enter - to search down
shift+enter - to search up

When you are in the text editor vi or you are using vim-mode in Atom ( vim-mode is an Atom plugin)

vi’ - to select between single quotes

ci’ - to delete between single quotes and enter into edit mode

:12 - to go to line 12

12gg - to go to line 12

:0 ⏎ - go to the top
takes you to line zero
GG - go to last line

$ - go to end of line

^ - go to the begining of the line

dd - to delete the current line

v/[string to search to] ⏎ - select from cursor to search string
n - to go to next match
shift+V[line number]G

kill line to left

ATOM ctrl-dir-scroll
When you are in the text editor Atom and using this plugin that models Sublime text editor functionality ( ctrl-dir-scroll is an Atom plugin)

ctrl+alt+↑ - scroll up 1 line

ctrl+alt+↓ - scroll down 1 line

ctrl+alt+shift+↑ - scroll up 10 lines

ctrl+alt+shift+↓ - scroll down 10 lines

READLINE (Command line shell)
These will work when you are in the terminal (command line.) These are picked up by the GNU Readline library which is embedded in Bash, other shells and many other pieces of software. Readline is a line editor as apposed to a a multiline editor.

ctrl+shift+2 (ctrl+@) - bookmark cursor location

ctrl+x+x - return to bookmark

ctrl+r enter search term - to search history
(hit ctrl+r if you want to search the next match)

ctrl+_ - to undo the previous change

esc+. - to pull in the last argument from the previous command

esc+t - to switch parameters

ctrl+w - delete word to the right
Also in works in Atom
esc+d - delete word to the left

ctrl+k - kill line to the right
Also in universalish keys
ctrl+u - kill line to the left
Also works in Atom
esc+f - move forward a word
We mapped ctrl+→ in Iterm to send these to the terminal. But just in case you find your self on another persons system this will work
esc+b - move back a word
We mapped ctrl+← in Iterm to send these to the terminal. But just in case you find your self on another persons system this will work

A replacement for the preloaded mac terminal application, it has a its own hot key bindings as well for when you are in the terminal using readline.

to copy text
1.) cmd+f
2.) type text
3.) tab (select right) or shift+tab (select left)
4.) esc
5.) cmd+c (to copy)
6.) cmd+p (to paste)

comments powered by Disqus