Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KonTrax/5182733 to your computer and use it in GitHub Desktop.
Save KonTrax/5182733 to your computer and use it in GitHub Desktop.

Sublime Text Cheat Sheet

Jeff Miller, 23 January 2013

Useful URLs

Command Palette

  • Open Palette: Ctrl+Shift+P (Tools > Command Palette...)

Goto Anything

  • Go to file: Ctrl+P (Goto > Goto Anything...)
  • Go to symbol: Ctrl+P, "@symbol" (Ctrl+R, Goto > Goto Symbol...)
  • Go to line number: Ctrl+P, ":#" for line (Ctrl+G, Goto > Goto Line...)
  • Go to word: Ctrl+P, "#word" (Ctrl+;)

Editing

  • Insert line after: Ctrl+Enter
  • Insert line before: Ctrl+Shift+Enter
  • Repeat last keyboard command: Ctrl+Y (Edit > Repeat)
  • Transpose: Ctrl+T (Edit > Text > Transpose)
  • (Un)Comment current line: Ctrl+/ (Edit > Comment > Toggle Comment)
  • Block (un)comment current selection Ctrl+Shift+/ (Edit > Comment > Toggle Block Comment)
  • Paste and indent correctly: Ctrl+Shift+V (Edit > Paste and Indent)
  • Uppercase: Ctrl+K, Ctrl+U (Edit > Convert Case > Upper Case)
  • Lowercase: Ctrl+K, Ctrl+L (Edit > Convert Case > Lower Case)

Line Operations

  • Indent current line(s): Ctrl+] (Edit > Line > Indent)
  • Unindent current line(s): Ctrl+[ (Edit > Line > Unindent)
  • Move line/selection up: Ctrl+Shift+Up (Edit > Line > Swap Line Up)
  • Move line/selection down: Ctrl+Shift+Down (Edit > Line > Swap Line Down)
  • Duplicate lines: Ctrl+Shift+D (Edit > Line > Duplicate Line)
  • Join lines: Ctrl+J (Edit > Line > Join Lines)

Deleting

  • Delete word forwards: Ctrl+Del
  • Delete word backwards: Ctrl+Backspace
  • Delete line: Ctrl+Shift+K (Edit > Line > Delete)
  • Delete from cursor to end of line: Ctrl+K, Ctrl+K
  • Delete from cursor to start of line: Ctrl+K, Ctrl+Backspace

Selection (can Be Repeated Multiple Times)

  • Select line: Ctrl+L (Selection > Expand Selection to Line)
  • Select word: Ctrl+D (Selection > Expand Selection to Word)
    • Skip selection: Ctrl+K, Ctrl+D
    • Undo last selection: Ctrl+U
  • Select scope: Ctrl+Shift+Space (Selection > Expand Selection to Scope)
  • Select brackets: Ctrl+Shift+M (Selection > Expand Selection to Brackets)
  • Select indentation: Ctrl+Shift+J (Selection > Expand Selection to Indentation)
  • Select tag: Ctrl+Shift+A (Selection > Expand Selection to Tag)
  • Scroll to selection: Ctrl+K, Ctrl+C (Goto > Scroll > Scroll to Selection)

Navigation

  • Jump to matching bracket: Ctrl+M (Goto > Jump to Matching Bracket)
  • Jump to your last change: Ctrl+U (Edit > Undo Selection > Undo) (repeat to undo change)

Bookmarks

  • Toggle bookmark: Ctrl+F2 (Goto > Bookmarks > Toggle Bookmark)
  • Next bookmark: F2 (Goto > Bookmarks > Next Bookmark)
  • Previous bookmark: Shift+F2 (Goto > Bookmarks > Previous Bookmark)
  • Select all bookmarks: Alt+F2 (Goto > Bookmarks > Select all Bookmarks)

Find/replace

  • Find: Ctrl+F (Find > Find...)
  • Find Next: F3 (Find > Find Next)
  • Find Previous: Shift+F3 (Find > Find Previous)
  • Replace: Ctrl+H (Find > Replace...)
  • Find in files: Ctrl+Shift+F (Find > Find in Files...) (Navigate using F4, Shift+F4)

Code Folding:

  • Fold: Ctrl+Shift+[ (Edit > Code Folding > Fold)
  • Unfold: Ctrl+Shift+] (Edit > Code Folding > Unfold)
  • Unfold all: Ctrl+K,Ctrl+J (Edit > Code Folding > Unfold All)
  • Fold attributes: Ctrl+K,Ctrl+T (Edit > Code Folding > Fold Tag Attributes)

Macros

  • Record: Ctrl+Q (Tools > Record Macro)
  • Playback: Ctrl+Shift+Q (Tools > Playback Macro)

Tabs

  • Previous tab: Ctrl+PgUp (Goto > Switch File > Previous File)
  • Next tab: Ctrl+PgDown (Goto > Switch File > Next File)
  • Switch to tab number: Alt+number (Goto > Switch File > ...)

Split Layout

  • Set single layout: Alt+Shift+1 (View > Layout > Single)
  • Set # columns: Alt+Shift+2,3,4 (View > Layout > Columns)
  • Set 2 or 3 rows: Alt+Shift+8,9 (View > Layout > Rows)
  • Set 2x2 grid: Alt+Shift+5 (View > Layout > Grid)
  • Move to group #: Ctrl+# (View > Focus Group)
  • Move file to group #: Ctrl+Shift+# (View > Move file to Group)

Organization

  • Toggle side bar: Ctrl+K, Ctrl+B (View > Side Bar > Hide Side Bar)
  • Distraction free: Shift+F11 (View > Enter Distraction Free Mode)
  • Enable spell-check: F6 (View > Spell Check) (Navigate using Ctrl+F6, Ctrl+Shift+F6)

Multiple Cursors

  • Press Ctrl then click in each region
  • Ctrl+Shift+L (Selection > Split into Lines)
  • Highlight word, press Ctrl+D (Selection > Expand Selection to Word) repeatedly to select additional occurrences of that word.
  • Add cursor at all occurrences of a word with Alt+F3 (Find > Quick Find All)
  • Add new line with cursor: Ctrl+Alt+Up, Ctrl+Alt+Down (Selection > Add Previous Line)
  • Return to single selection: Esc (Selection > Single Selection)
  • You can select a rectangular selection by using Shift, then holding the right mouse button and dragging over the area you wish to select. You can remove part of the selection using Shift+Alt.

Marking

  • Set mark: Ctrl+K, Ctrl+Space (Edit > Mark > Set Mark)
  • Select to mark: Ctrl+K, Ctrl+A (Edit > Mark > Select to Mark)
  • Delete to mark: Ctrl+K, Ctrl+W (Edit > Mark > Delete to Mark)
  • Switch location with mark: Ctrl+K, Ctrl+X (Edit > Mark > Swap with Mark)
  • Clear Mark: Ctrl+K, Ctrl+G (Edit > Mark > Clear Mark)

Projects

  • Switch Project: Ctrl+Alt+P (Project > Switch Project in Window...)
  • Select root folder: Project > Add Folder to Project...
  • Save: Project > Save Project As... (.sublime-project file)

Miscellaneous

  • Show scope in status bar: Ctrl+Alt+Shift+P
  • Re-indent Lines: Edit > Line > Reindent
  • Close Tag: Alt+.
  • Reopen Closed File: Ctrl+Shift+T (File > Open Recent... > Reopen Closed File)
  • See Key Bindings: Preferences > Key Bindings - Default
  • TextMate Theme Compatible: Themes Bundle (extract to "%AppData%\Sublime Text 2\Packages")
  • A list of all installed packages is in "%AppData%\Sublime Text 2\Packages\User\Package Control.sublime-settings" (see "installed_packages")

Command Line Script

Save as "subl.cmd" in your path, and run it. Supports wildcards.

@ECHO OFF
REM 2012-12-30 Jeff Miller
SETLOCAL

CALL :GetStPath
IF "%StPath%"=="" ( ECHO Can't find Sublime Text & GOTO :EOF )

PATH %StPath%;%PATH%

set LIST=
:NEXTARG
IF "%~1"=="" GOTO :START
FOR %%i IN (%1) DO CALL :ADDARG "%%~fi"
SHIFT
GOTO :NEXTARG
:ADDARG
SET LIST=%LIST% %1
GOTO :EOF

:START
START "Sublime Text" sublime_text.exe --add %LIST%
GOTO :EOF

:GetStPath
SETLOCAL
FOR /F "skip=2 delims=" %%f IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Sublime Text 2_is1" /v InstallLocation') DO SET P=%%f
ENDLOCAL & SET StPath=%p:~33%
GOTO :EOF

Forcing Windows to use substitute font if "Menlo" is referenced

Add the following to the registry and then reboot. Requires DejaVu Fonts to be installed first.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"Menlo"="DejaVu Sans Mono"

My User Settings

Prerequisites:

  1. Install Nexus theme.
  2. Install Inconsolata font.

Preferences > Settings - User :

{
    "bold_folder_labels": true,
    "caret_style": "phase",
    "color_scheme": "Packages/Theme - Nexus/Nexus.tmTheme",
    "detect_indentation": false,
    "draw_minimap_border": false,
    "ensure_newline_at_eof_on_save": true,
    "fade_fold_buttons": false,
    "font_face": "Inconsolata",
    "font_size": 12,
    "font_options": [
        "directwrite"
    ],
    "font_size": 10,
    "highlight_line": true,
    "highlight_modified_tabs": true,
    "hot_exit": false,
    "ignored_packages": [
        "Vintage",
        "ZenCoding"
    ],
    "indent_guide_options":
    [
        "draw_active"
    ],
    "line_numbers": false,
    "line_padding_bottom": 1,
    "line_padding_top": 1,
    "rulers": [
        80,
        120
    ],
    "spell_check": true,
    "tab_size": 4,
    "theme": "Nexus.sublime-theme",
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "use_tab_stops": true
}

PACKAGES I USE

File Creation Plugin.

  • Create New File: Ctrl+Alt+N

Preferences > Package Settings > AdvancedNewFile > Settings - User :

{
    "alias": {
        "desktop": "C:/Users/jeff/Desktop/",
        "temp": "C:/Users/jeff/AppData/Local/Temp"
    }
}

Automatically Save Off A Backup Of Your Files Each Time You Save A File.

  • Backwards in history: Ctrl+Alt+[
  • Forwards in history: Ctrl+Alt+]
  • Merge from backup history: Ctrl+Alt+Shift+M

Preferences > Package Settings > Automatic Backups > Settings - User :

{
    "backup_dir": "D:/Backups",
    "backup_merge_command": "C:/Program Files (x86)/Beyond Compare 2/BC2.exe \"{oldfilepath}\" \"{curfilepath}\""
}

Bracket And Tag Highlighter.

Preferences > Package Settings > Bracket Highlighter > Settings - User :

{
    "angle_style": "underline",
    "curly_style": "underline",
    "quote_style": "underline",
    "round_style": "underline",
    "square_style": "underline",
    "tag_style": "underline"
}

Remember, restore and sync scroll, bookmarks, marks, folds and cursors.

Keep a history of your clipboard items.

  • Show History: Ctrl+Alt+V
  • Paste Previous History Entry: Ctrl+Shift+V
  • Paste Newer History Entry: Ctrl+Shift+Alt+V

CTags Support.

  • Find > CTags
  • Rebuild Tags: Ctrl+T, Ctrl+R
  • Navigate to Definition: Ctrl+T, Ctrl+T
  • Search for Definition: Ctrl+T, Ctrl+Y
  • Jump Back: Ctrl+T, Ctrl+B
  • Show Symbols: Alt+S (multi: Alt+Shift+S, language: Ctrl+Alt+Shift+S)

Make Writing Documentation A Breeze. Supports Javascript, Php, Actionscript, Coffeescript, Java, Objective C, C And C++.

  • /**< Enter >
  • /* < Enter >
  • /**< Enter >function foobar (baz, quux) { } - where function (or variable definition) already exists. Shift-Enter will place the definition inline.
  • Decorate comment: // foo!< Ctrl+Enter >

Emmet (previously Called Zen Coding).

  • Documentation
  • div#page.section< Tab > becomes <div id="page" class="section"></div>
  • div[title="Hello"]< Tab > becomes <div title="Hello"></div>
  • li.item$*3< Tab > becomes <li class="item#"></li> (3 times)
  • p>{Click }+a{here}+{ to continue}< Tab > becomes <p>Click <a href="">here</a> to continue</p>
  • div#page>(div#header>ul#nav>li*4>a{Item $})+(div#page>(h1>span)+p*2)+div#footer< Tab >

Export code to HTML for copying/printing/saving.

  • Ctrl+Shift+P, Export to HTML: Show Export Menu

Shows Diffs Between The Current File, Or Selection(s) In The Current File, And Clipboard, Another File, Or Unsaved Changes.

Preferences > Package Settings > FileDiffs > Settings - Default :

For Beyond Compare 2:

{
    "cmd": [
        "C:/Program Files (x86)/Beyond Compare 2/BC2.exe",
        "$file1",
        "$file2"
    ],
    "open_in_sublime": false
}

Assist In Finding Key Conflicts Between Various Plugins.

  • Ctrl+Shift+P, FindKeyConflicts

Generate Uuid.

  • Generate UUID: Ctrl+Shift+U

Git Integration.

  • Wiki
  • Install Git using “Run Git from the Windows Command Prompt”
  • Tools > Git

Allows The Toggling Of A File Into A Hex Viewing Mode.

  • Tools > Packages > Hex Viewer
  • NOTE: Shortcuts conflict with "build"
  • Toggle hex editor mode: Ctrl+Shift+B, Ctrl+Shift+H
  • Show hex inspector: Ctrl+Shift+B, Ctrl+Shift+I

Preferences > Package Settings > Hex Viewer > Settings - User :

{
    "auto_open": true,
    "auto_open_patterns": [
        "*.bin",
        "*.dll",
        "*.ico",
        "*.lib",
        "*.pyc",
        "*.exe",
        "*.res"
    ],
    "bytes_per_line": 16,
    "custom_font": "Consolas",
    "custom_font_size": 12,
    "group_bytes_by_bits": 8,
    "inspector": false
}

Highlight mutiple words in different colors.

  • Highlight Words: Ctrl+Alt+H (Edit > Highlight Words > Highlight Words)
  • Unhighlight Words: Ctrl+Alt+U (Edit > Highlight Words > Unhighlight Words)

HTML5 bundle.

INI Syntax Highlighting.

Preview Your Markdown Files Quickly In Your Web Browser.

  • Ctrl+Shift+P, Markdown Preview

Open URLs, Files, Folders, Or Google Text Under The Cursor Or In Selected Text.

  • Open URL: Ctrl+U

Split the window however you like!

  • Ctrl+K then press the arrow keys with modifiers:
    • (no modifiers): travel to an adjacent pane
    • Shift: carry the current file to the destination
    • Alt: clone the current file to the destination
    • Ctrl: create an adjacent pane
    • Ctrl+Shift: destroy an adjacent pane

A Full-featured Package Manager That Helps Discovering, Installing, Updating And Removing Packages.

Ctrl+` then paste:

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'
  • Ctrl+Shift+P, Install Package (Preferences > Package Control)

An opinionated todo-list plugin

  • Tutorial: Preferences > Package Settings > PlainTasks > Tutorial
  • Create list: Ctrl+Shift+P, Tasks: New document
  • New Task: Ctrl+Enter (or Ctrl+I)
  • Task Complete (toggle): Ctrl+D

Support For The Ms PowerShell 2 Programming Language.

Prettify JSON.

  • Prettify: Ctrl+Alt+J

Preferences > Package Settings > Pretty JSON > Settings - User :

{
    "ensure_ascii": true,
    "indent": 4,
    "sort_keys": true,
    "use_entire_file_if_no_selection": true
}

Provides Enhancements To The Operations On Side Bar Of Files And Folders.

  • Open current file in browser: F12 (NOTE: doesn’t support IE)

Html, Css And Javascript Code Formatter.

  • Requires Node.js
  • Prettify: Ctrl+Shift+P, htmlprettify

Highlights Lines Of Code The Linter Deems To Contain (potential) Errors.

Preferences > Package Settings > SublimeLinter > Settings - User :

{
    "sublimelinter": "load-save",
    "sublimelinter_executable_map": {
        "c": "C:/Program Files/cppcheck/cppcheck.exe",
        "css": "C:/Program Files/nodejs/node.exe",
        "javascript": "C:/Program Files/nodejs/node.exe"
    },
    "sublimelinter_gutter_marks": true,
    "sublimelinter_popup_errors_on_save": true
}

Edit simple text tables in text mode.

  • Usage: Preferences > Package Settings > Table Editor > README
  • Demo: Ctrl+Shift+P, Table Editor: Show demo film in new scratch view

Collection Of Packages About Tags.

  • Edit > Tag
  • Put matching closing tag: Alt+.

Dark Custom Ui Theme.

VBScript Package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment