Sublime Text used to be a good code editor for many languages and for many programmers. There are many better ones these days but I still use it for quickly modify a file which doesn’t exist in any working project. Here are some Sublime Text tips that I use daily:
Table of Contents
9 Sublime Text Tips
All hotkeys below are for Windows. For Mac users, just replace Ctrl
with Command
.
Split window for a file
Many files contain thousands lines of codes. Sometimes a task required to have different lines be compared or edited at the same time. That’s why we need to view different parts of the same file with clone or split view.
File > New View into File
View > Layout > Columns: 2
orRows: 2
- Drag a tab to other view
Browse a file by name
The editor provides a shortcut which allows you to find a file inside your working directory and you know the name of that file.
Ctrl + P
This hotkey open a popup where you can type in a part of a file’s name to search for it.
Show unsaved changes
You can right-click on an opening file then click on Show Unsaved Changes...
to reveal recently changes which haven’t been saved.
Input a HTML tag
With Alt + Shift + W
you can place an tag with both opening and closing syntax. By default it places p
tag, but you can type in any HTML tags you want to replace it.
To wrap a block of text with a tag, you can highlight that block and press Alt + Shift + W
.
Search within entire project
Finding a file is something we already know, but Sublime Text make it better with the ability to search an entire project folder.
Press Ctrl + Shift + F
to open the search box. You can input any directory to search within it.
Duplicate current line
You can place the mouse cursor on a line then press Ctrl + Shift + D
. This action will copy the entire current line and duplicate it below.
Move line up or down
Moving lines of codes around with copy and paste is slow. That’s why Sublime Text provides us a shortcut to shift a line up or down.
Ctrl + Shift +
Up for moving up a line.
Ctrl + Shift + Down
for moving down a line.
Delete current line
Sublime Text also has a method for deleting the entire current line, even if nothing is highlighted.
Ctrl + Shift + K
Auto save
I have a habit of pressing Ctrl + S
every line of code written. If you are like me, using this feature will help a lot.
Open Preferences > Settings
and add this line:
"save_on_focus_lost": true
Best Sublime Text Plugins
- Package Control – This is the must-have package as it helps in installing, downloading and updating of other plugins.
- Alignment – This package takes your code and aligns the configured characters vertically. It is a nice tool to align characters like
=>
,(
for array in language like PHP. - Emmet – Emmet is a plugin for many popular text editors which greatly improves HTML & CSS workflow. It turn ul#menu>li*2 into
<ul id="menu">
<li></li>
<li></li>
</ul>
- SublimeLinter – SublimeLinter is a plugin for Sublime Text that provides a framework for linting code.
- SASS – This is SCSS and Sass syntax, including completions for CSS properties and values, as well as relevant Sass functions.
- Babel – It provides language definitions for ES6+ JavaScript with the extensions of React JSX syntax.
- GhostText – Everything you type in the editor will be instantly updated in the browser (and vice versa). It is a real time-saver.
- SublimeGit – If you’re used to Git and dealing with Sublime Text packages, you can probably just install SublimeGit, and get right to work.
- DocBlockr – This package helps writing documentation and simplify writing DocBlock comments in Javascript, PHP, CoffeeScript, Actionscript, C & C++.
- SideBarEnhancements – It provides enhancements to the operations on Sidebar of Files and Folders.
- Minifier – Minifier supports Google Closure Compiler for Javascript minification and cssminifier or Reducisaurus for CSS minification.
Sublime Text Hotkeys
Editing | |
Cut line | Cut line |
Insert line after | Ctrl + Backspace |
Insert line before | Ctrl + Shift + Backspace |
Move line/selection up | Ctrl + Shift + ArrowUp |
Move line/selection down | Ctrl + Shift + ArrowDown |
Select line – Repeat to select next lines | Ctrl + L |
Select word – Repeat select others occurrences | Ctrl + D |
Jump to closing parentheses Repeat to jump to opening parentheses | Ctrl + M |
Select all contents of the current parentheses | Ctrl + Shift + M |
Delete Line | Ctrl + Shift + K |
Delete from cursor to end of line | Ctrl + KK |
Delete from cursor to start of line | Ctrl + K + ⌫ |
Indent current line(s) | Ctrl + ] |
Un-indent current line(s) | Ctrl + [ |
Duplicate line(s) | Ctrl + Shift + D |
Join line below to the end of the current line | Ctrl + J |
Comment/un-comment current line | Ctrl + / |
Block comment current selection | Ctrl + Shift + / |
Redo, or repeat last keyboard shortcut command | Ctrl + Y |
Paste and indent correctly | Ctrl + Shift + V |
Select next auto-complete suggestion | Ctrl + Space |
soft undo; jumps to your last change before undoing change when repeated | Ctrl + U |
Wrap Selection in html tag | Alt + Shift + W |
Close current html tag | Alt + . |
Column selection up | Ctrl + Alt + Up |
Column selection down | Ctrl + Alt + Down |
Navigation/Goto Anywhere | |
Quick-open files by name | Ctrl + P |
Goto symbol | Ctrl + R |
Goto word in current file | Ctrl + ; |
Goto line in current file | Ctrl + G |
General | |
Command prompt | Ctrl + Shift + P |
Toggle side bar | Ctrl + KB |
Show scope in status bar | Ctrl + Shift + Alt + P |
Find/Replace | |
Find | Ctrl + F |
Replace | Ctrl + H |
Find in files | Ctrl + Shift + F |
Tabs | |
Open last closed tab | Ctrl + Shift + t |
Cycle up through tabs | Ctrl + PgUp |
Cycle down through tabs | Ctrl + PgDn |
Find in files | Ctrl + Tab |
Close current tab | Ctrl + W |
Switch to tab number [NUM] where [NUM] <= number of tabs | Alt + [NUM] |
Split window | |
Revert view to single column | Alt + Shift + 1 |
Split view into two columns | Alt + Shift + 2 |
Split view into three columns | Alt + Shift + 3 |
Split view into four columns | Alt + Shift + 4 |
Set view to grid (4 groups) | Alt + Shift + 5 |
Split view into two rows | Alt + Shift + 8 |
Jump to group where num is 1-4 | Ctrl + [NUM] |
Move file to specified group where num is 1-4 | Ctrl + Shift + [NUM] |
Bookmarks | |
Toggle bookmark | Ctrl + F2 |
Next bookmark | F2 |
Previous bookmark | Shift + F2 |
Clear bookmarks | Ctrl + Shift + F2 |
Text manipulation | |
Transform to Uppercase | Ctrl + KU |
Transform to Lowercase | Ctrl + KL |