43

Macs are renowned (or bemoaned) for having an extensive number of shortcuts. However, OS X itself pales in comparison to the shortcut lists in TextMate and its bundles.

What are some useful keyboard shortcuts you use?

Michiel de Mare
  • 41,982
  • 29
  • 103
  • 134
Tony Pitale
  • 1,192
  • 2
  • 11
  • 23
  • 1
    Why not just contribute to an existing thread and turn it into a community wiki? http://stackoverflow.com/questions/2391247/textmate-tips-for-rails-development and http://stackoverflow.com/questions/99807/what-are-some-useful-textmate-shortcuts – Peter Brown Jan 03 '11 at 17:26
  • I did see those posts. However, I didn't really like the format. Cheatsheets and plugins mixed with tips, etc. That's not really what I'm after. I'm hoping to encourage a massive list of tips similar to the unix tips thread I posted. – Cory Schires Jan 03 '11 at 17:43

30 Answers30

42

These are my favorite shortcuts:

  • cmd+t Start typing name of a file to open it
  • ctrl+w Select word
  • cmd+r Run the ruby or php-script that is open
  • cmd+opt+m Define a new macro
  • cmd+shift+m Run the macro
  • opt Switch to vertical selection mode
  • cmd+opt+a Edit ends of selected lines
mtb
  • 1,350
  • 16
  • 32
Magnar
  • 28,550
  • 8
  • 60
  • 65
21
  • ctrl+shift+K deletes current line
  • ctrl+shift+J merges current line with the next line
mtb
  • 1,350
  • 16
  • 32
melfar
  • 360
  • 3
  • 16
12

Esc auto completes common words in the document you are working in.

For example if you are using a function alot called LongFuntionNameThatChecksStuff, you can type Lon and pressEsc and it should auto complete.

mtb
  • 1,350
  • 16
  • 32
Eric Van Joshnon
  • 191
  • 2
  • 13
  • 3
    This loops thru the matching words in order of nearness to your cursor. So might need to hit the escape key a few times to get what you're after. – Cory Schires Jan 03 '11 at 17:57
  • I did not know that.. I always assumed it just picked the most common word. That just became a whole lot more useful, thanks – Eric Van Joshnon Jan 03 '11 at 18:00
9

Control-T(ControlT): Transpose (works in most Cocoa-native text fields and areas, but TextMate enhances the behavior).

  • Place your caret between two characters, hit ControlT, and the characters switch places (this is standard Mac behavior). Awesome for typos.

  • Select a word or series of characters on a single line, hit ControlT, and the characters in the selection will now be reversed (not too useful, but this is a TextMate enhancement)

  • Select a series of characters that spans more than one line, hit ControlT, and the lines will reverse. Characters within the line will still be in order. Most useful when selecting whole lines, but still works with partial lines selected, just so long as there is at least one newline character selected (TextMate enhancement).

Stephan
  • 41,764
  • 65
  • 238
  • 329
drukepple
  • 364
  • 1
  • 4
  • 8
  • Exactly what I was looking for, thanks! I was searching the menu for "reverse", "flip", "invert", etc. so I could flip some lines around. – robyoder Nov 19 '14 at 17:42
8

My favourites are:

  • option+command+[ to clean up your indentation
  • "lorem", TAB to insert placeholder text
mtb
  • 1,350
  • 16
  • 32
alamodey
  • 14,320
  • 24
  • 86
  • 112
7

Personally two of my favourite shortcuts are:

  • ⌃⇧L (that's ctrl+shift+L): Which wraps the currently selected text with a link to whatever's in the clipboard, and works for every text language I've tried it in.
  • ⌃⇧⌘L (that's ctrl+shift+cmd+L): Which googles for the selected text and links to the top result.

The are both super useful for writing text and blogging, (and stackoverflow).

Codewise, I think that I prefer snippets to key shortcuts. Being able to type if⇥ etc., in almost any language is ridiculously useful, and the consistent interface is what keeps me using TextMate.

I also found this quite amusing. But I prefer to learn my shortcuts in small steps, and often find that just looking in the gear menu (⌃⎋) works.

mtb
  • 1,350
  • 16
  • 32
Matt
  • 5,522
  • 5
  • 29
  • 24
5

shift+ctrl+alt+v sends selected text to pastie.org

also, using the PHP Bundle, try to start writing a function name and do the following:

str + alt + F3 = list of available functions

str + alt + F1 = short description of the function you've just completed.

svnlto
  • 39
  • 2
  • 3
5

Look word up in dictionary, in any Cocoa app (not just Textmate): ctrl + cmd + D

alt text

Pontus Granström
  • 1,089
  • 8
  • 18
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
4

Wrap each selected line in markup tags: SHIFT + CONTROL + COMMAND + W

For example, if you have:

  This is a 
  few sample
  list items 

Highlight all three lines and presss SHIFT + CONTROL + COMMAND + W to create:

  <li>This is a </li>
  <li>few sample</li>
  <li>list items</li>
mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
4

Generate Lorem ipsum: lorem + TAB

Will generate:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
3

Selecting text using alt (via click and drag)

then use + ] to indent (or [ to dedent)

mtb
  • 1,350
  • 16
  • 32
sethvargo
  • 26,739
  • 10
  • 86
  • 156
3

Delete the current line: CONTROL + SHIFT + K

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
3

Format CSS: CONTROL + Q

Select some CSS and press CONTROL + Q to turn this:

body { background: red; font-size: 10px; color: black; }

Into this:

body {
  background: red;
  font-size: 10px;
  color: black;
}
mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
3

Look up property specifications in W3C: CONTROL + H

This works for both HTML and CSS. Place your carrot over whatever property you'd like to look up and press CONTROL + h. This will open a new window listing the W3C info.

For example, place your carrot over background:

body {
  background: red;
}

Hit command + h and you'll see something like:

alt text

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
3

Edit the end of multiple selected lines simultaneously : COMMAND + OPTION + A

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
3

Toggle between {} and do end blocks. Place your cursor on the block arugument (i.e. the word after the keyword do between the two pipes) and press Shift + Control + {

For example, converts:

@post.each do |post|
  puts post.name
end

to:

@post.each { |post| puts post.name }
mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
3

CMD + / comments out a line and it's smart enough to format based on language. I use it all the time.

mtb
  • 1,350
  • 16
  • 32
Justin Thiele
  • 376
  • 3
  • 6
2

Close the nearest open html/xml tag: OPTION + COMMAND + PERIOD

For example, if you have:

<div>Lorem ipsum dolor sit amet, consectetur

CONTROL + COMMAND + D will automatically add the closing </div> tag to create:

<div>Lorem ipsum dolor sit amet, consectetur</div>
mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
2

Switch between tabs:

  • Left: SHIFT + COMMAND + [
  • Right: SHIFT + COMMAND + ]
mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
1

You can get a really great desktop background here. It has a ton of really useful keyboard shortcuts. I used it for a couple of days before memorizing the most useful ones.

Nate Smith
  • 1,103
  • 1
  • 15
  • 19
  • That link died, but here's another: [http://blog.libinpan.com/2009/08/textmate-shortcuts-desktop](http://blog.libinpan.com/2009/08/textmate-shortcuts-desktop/) – yalestar Mar 15 '11 at 15:45
1

Wrap selected text in markup tags: SHIFT + CONTROL + W

For example, if you have:

Lorem ipsum dolor sit amet, consectetur

Highlight the text and press SHIFT + CONTROL + W to create:

<p>Lorem ipsum dolor sit amet, consectetur</p>
mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
1

Go to File: + T

Find in Project: + SHIFT + F

mtb
  • 1,350
  • 16
  • 32
Kevin Sylvestre
  • 37,288
  • 33
  • 152
  • 232
1

Eliminate all whitespace / carriage returns between the location of your caret and the start of the next piece of content: SHIFT + CONTROL + J

For example, if you have:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip.

Place your caret at the end of the first paragraph and press SHIFT + CONTROL + J to remove the space in between the paragraphs:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip.

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
1

in the cftextmate bundle you can type any cfml tag without the opening "<" or closing ">" and press tab and it completes the entire tag and you can then tab to each of the tag attributes. i'm not sure if this type of shortcut works for other languages.

ethyreal
  • 3,659
  • 2
  • 21
  • 25
1

I just found a list of shortcut key symbols w/ definitions under Bundles > HTML > Entities - helpful for me in figuring out the whole short-cut bonanza going on with TextMate.

micahwittman
  • 12,356
  • 2
  • 32
  • 37
0

(these are mostly html-related)

  • cmd + option + closes current open html tag
  • shift + cmd + w wrap selection in tags
  • ctrl + return insert escaped line end, i.e. \n or <br> depending on the occasion.
mtb
  • 1,350
  • 16
  • 32
Agos
  • 18,542
  • 11
  • 56
  • 70
0

Copy and Paste Clipboard: + SHIFT + V

mtb
  • 1,350
  • 16
  • 32
Eric Van Joshnon
  • 191
  • 2
  • 13
  • Whoa. I didn't know about this. It's a bit different than the standard paste (⌘+v). It seems to move backward thru your clipboard history with each paste. Nice. – Cory Schires Jan 03 '11 at 18:12
  • And the nice thing about it is that it includes the clipboard history outside of the Textmate application – Eric Van Joshnon Jan 03 '11 at 18:24
0

Titleize selected text: CONTROL + OPTION + U

Will turn:

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Into:

Lorem Ipsum Dolor Sit Amet, Consectetur Adipisicing Elit.

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
0

Downcase selected text: CONTROL + SHIFT + U

Will turn:

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Into:

lorem ipsum dolor sit amet, consectetur adipisicing elit.

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26
0

Upcase selected text: CONTROL + SHIFT + U

Will turn:

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Into:

LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISICING ELIT.

mtb
  • 1,350
  • 16
  • 32
Cory Schires
  • 2,146
  • 2
  • 14
  • 26