Supercharge your Sublime Text 3 to increase your productivity

Written by arshamshirvani | Published 2017/01/07
Tech Story Tags: coding | programming | sublimetext | sublime-text-3 | productivity

TLDRvia the TL;DR App

(Edit) I have added some gif to this article.

I’m glad you like Sublime Text 3! In fact, I am a die hard fan and I’ve been using it for ages (since ST2). I have a few tricks I would like to share them with you.

This is not a language oriented article.

This article ranges from basics to advanced use of ST3 and we are going to learn and do:

  • Fuzzy searching basics.
  • What the files under User folder are.
  • Some important functionalities as a reminder.
  • Working with words and lines. Selection and deleting techniques.
  • Useful keys and advance navigation techniques.
  • Project Management.
  • Install a few handy plugins.
  • Optimisation by changing a few settings.
  • Add missing commands to the Command Palette.

In case you don’t know how to open the Command Palette, hit ctrl+shift+p. The ctrl+p is for go to files, otherwise known as go to anything.

Fuzzy searching

It works like this: if you are after a term in any palettes, for instance Preferences: Key Bindings , you don’t need to type in the whole thing. I would do kybi which matches the term. Also there is no space needed.

Files under User folder

There are some files under ~/.config/sublime-text-3/Packages/User . I’m using GNU/Linux, but the principals are the same in other OSs. The contents should be in valid JSON format, otherwise they don’t work.

The Preferences.sublime-setting is for global settings. It can be accessed by command palette (Preferences: Settings).

The Default (Linux).sublime-keymap is where you can add key shortcuts. It can be accessed in command palette (Preferences: Key Bindings).

The Default (Linux).sublime-mousemap contains the mouse actions. For now you only can open it by browsing to the directory and edit. However in this article I will show you how to add it to the Command Palette with ease.

There is another kind of file that doesn’t exist in that folder by default but you can create one, which extends the Command Palette functionalities, I will explain it in below.

Basic functionalities and concepts

Multi cursor can be invoked in any of these ways:

Select multiple lines, then hit ctrl+shift+l

ctrl+left-click on different places

Find under expand. Put your cursor on a word, then hit ctrl+d it will select that word. Then hit ctrl+d a few more times to find similar words while creating a new cursor. It also works with partially selected words (a few characters or a few words/lines).

Find all: ctrl+f and click on Find All

Reveal file in sidebar shows the current file’s location in the sidebar and highlights it. Right click on the view and choose Reveal In Sidebar . We will create a command for it below as it doesn’t exists (yet).

Toggle Sidebar by hitting ctrl+k ctrl+b . You can create a command for this one too if you want.

Go To Anything is an important one. You can invoke its palette by ctrl+p . It shows you a list of available files in your current project (see below). It too obeys the fuzzy searching rules. Here are more things you can do with it:

  • @ shows a list of symbols (classes/functions/methods) you can navigate to.
  • : takes you to a line by typing the line number.
  • # shows you a list of token words (they can be set up in .tmLanguage files and they usually come with plugins you install)

If you don’t type in any file names, they work on the current file.

Always have a mental image of your project and possible symbol names and navigate with this palette.

Example 1:

If you want to go to a file called brew_beer.go and you know you want to land on a function called Ingredients() , type this in the palette: bre@ingrd . This is just an example and the letters don’t have any significance other than matching. You need to make sure the destination file is focused then add @ to the mix.

Example 2:

If you want to go to the line 18 of a file called drunk_snake.py , you can type in drnksnk:18 .

New View into File extremely useful for using in multiple panes (more about it in the origami section)

Scrolling while keeping the cursor at its position can be done by ctrl+up/down . Note that if you don’t have any selection, the cursor will travel by the edge of the view. In case you want to avoid and keep the cursor where it is, select one word and scroll. It retains the cursor position.

Wrap lines is handy when your lines are long and don’t fit into the view. You can invoke it with Command Palette.

Wrapping a paragraph can be done with alt+q . It uses the ruler position to wrap.

More useful actions will be mentioned in other sections of this article, please read on.

Working with Words and Lines

Let’s assume you have your cursor on a word/line and you want to:

Go to next/previous word: ctrl+right/left

Go to matching bracket: ctrl+m . It also works if you are not a bracket. It will navigate you to the closest bracket.

Select the current word: hit ctrl+d . Please do not go to the end/beginning of the word and do ctrl+shift+left/right , those combinations have a different purpose. It’s not what a ninja would do!

Select to next/previous word as you go: ctrl+shift+right/left

Delete to the end of a word: ctrl+delete

Delete to the beginning of a word: ctrl+backspace

Delete to the end of the line: ctrl+shift+delete

Duplicate lines: ctrl+shift+d

Delete current line all together: ctrl+x

Swap lines up/down**:** ctrl+shift+up/down

Expand Selection: ctrl+shift+space . It expands the selection in blocks, and expands more if you hit it more times until it selects the whole file.

Delete a block: hit ctrl+shit+space until you covered the block you want to remove, then delete.

Indent line(s) left: ctrl+[ and Indent line(s) right: ctrl+]

Jump forward and back (settings all the way down on this article): as you are moving around in your project, you can always go back and forth to the place you were. This is handy for inspecting the project.

Insert a tab where ST3 insists on a completion: shift+tab

(Edit 1) When you copy/cut stuff in ST3, it keeps them in a history. If you do ctrl+k ctrl+v it shows you a pop up of the history and you can choose to paste it. This is super useful!

Join Lines: ctrl+j

Project Management

Projects

Projects contain a series of files/folders added into a project. You can add multiple folders to a project if you wish. I have a folder in my Projects folder called Sublime Text where I keep all my ST3 projects. I also put them into their own sub-folder to manage different workspaces. I suggest you do the same as it clutters the whole folder if you work with a lot of projects. You can open the project settings by invoking Project: Edit in command palette. Here are a few tips:

"folders": [{"file_exclude_patterns": ["*.test", "*.out"],"folder_exclude_patterns": ["tmp"],],"path": "/path/to/project/folder",}],

Workspaces

You can have multiple workspaces per project. They share the same settings as their parent project, therefore when you change the project settings it applies to all of its workspaces. Use them if you have different layouts or you have different concerns while working on a project. You can save them in the same folder you keep your ST3 project by choosing Project> Save Workspace As.. menu. You can also create a brand new workspace for the current project from the Project menu.

Fast Switching Projects

Every time you open/create projects or workspaces, ST3 keeps a history of what you’ve been working on. You can then hit ctrl+alt+p to navigate between projects or workspaces easily.

Handy Plugins

Alignment is useful for aligning cursors. I have changed the key binding to

{ "keys": ["super+a"], "command": "alignment" }

Make a multi cursor and hit super+a to align them. It will move the text with which is really handy. You can create such sight in your file:

Bracket Highlighter shows you the opening and closing pairs of brackets. I use it to identify the block I am working on.

Case Conversion can change word/character cases. It has these modes:

  • snake_case
  • camelCase
  • PascalCase
  • dot.case
  • dash-case
  • Separate words
  • Separate with forward slashes
  • Separate with backslashes
  • Toggle between snake_case, camelCase and PascalCase

File Rename can change the file name. I use this to depend less on my mouse.

Git Gutter shows git changes in the gutter. You also can view the diffs and roll them back, really handy.

Jump Along Indent: I use it every all the times. You can land your cursor on an indented area (maybe a bracket or beginning of a line) and hit alt+up/down to jump to the respective indention.

HaoGist is a must have one if you do gists on github. Just generate a token on your github account (with only gist enabled permission) and add it to the plugin. You never need to browse to gists web page for your gists any more. You also can load a gist, edit and save it. It updates the gist automatically.

MoveTab can move your tabs like in your browser.

Increment Selection is useful if you increment numbers. Create a bunch of cursors and type 0 then select all those zeros and hit ctrl+alt+i . It makes a series of incremented numbers. You can seed it with any numbers.

PlainTasks is another must have plugin to make todo lists. It also tracks the time spent on each item. It is very straightforward and starts with its own tutorial when you install it, so there is no need to explain it here.

SideBarEnhancements will enhance your sidebar. Make sure you install this one.

Sublime Bookmarks is a better version of sublime’s bookmark system. You can name your bookmarks and navigate them in the command palette. Very handy.

Material Theme looks really cool, give it a go.

(Edit 1) MultiEditUtils: this awesome plugin adds some cool functionalities to multi-cursor functionality. For instance you can edit individual cursors while retaining the who multi-cursor state. You also can cycle through the cursors and edit them! Head over to its page to see the full description.

Origami : I mention this the last, because I also wanted to tell you a little story. Please read this part as I explain the decisions I have made to set this very important plugin.

I can’t live without tmux. The way ST3 handles panes is way primitive in comparison to tmux and my ST3 work flow has been a bit slow before I started using origami. Before using origami, I rarely utilised panes and only relied on goto anything. The very first time I saw origami, it blew my mind, but soon I left it for the following reasons:

  • The shortcuts were different than my tmux set up
  • It made me slower to code because it didn’t feel natural

My tmux prefix is ctrl+a and I couldn’t use it for origami because it is also select all functionality. Until I asked myself these questions:

  • How many times am I selecting the whole file’s contents in a day?
  • Which one contributes to my productivity: Selecting all or having a more flexible workspace?

The answer to the second question is obvious, duh! However the answer to the first question turned out very interesting: at most 10 times a day!

Now the other obstacle: How am I going to set these two up in such a way I can have best of both? Here is what I came up with, which worked amazingly well for me and I’ve been a happier programmer. I changed the select all to:

{ "keys": ["ctrl+a", "ctrl+a"], "command": "select_all" }

And changed all ctrl+b prefixes of origami to ctrl+a. Now here is what happens:

  • My pane control/navigation is exactly like the tmux set up, and it feels very natural to me.
  • If I want to select all, I do ctrl+a twice, why not?!

Problem resolved.

I also disabled creating empty panes, which is really annoying. This means if you do a ctrl+a right it creates an empty pane with nothing in it, which is not useful unless you want to create a new file. You can achieve that by creating a new file and move it to a new pane by ctrl+a shift+right. In origami’s user settings I have:

"create_new_pane_if_necessary": false,

And in the preferences I added this to close empty panes when the last file is closed:

"origami_auto_close_empty_panes": true

Now here is a few handy tricks for origami. I call it prefix here, the key I have set to ctrl+a which is ctrl+b by default. Lets call up/down/left/right arrow keys a direction. For instance this combination prefix, ctrl+direction means you hit ctrl+a then hit ctrl+up.

  • prefix, ctrl+direction creates pane on the direction.
  • prefix, ctrl+shift+direction destroys pane on that direction.
  • prefix, direction travels to the direction.
  • prefix, shift+direction travels while carries the file to the direction.
  • prefix, alt+direction clones (makes a new view on the file) while bringing the new view to the direction.
  • prefix, ctrl+z zooms the pane.
  • prefix, ctrl+shift+z un-zooms the pane back to normal.
  • prefix, ctrl+c shows you an input box to put in the proportion of pane’s horizontal (column) size. I’ll explain in a bit.
  • prefix, ctrl+r shows you an input box to put in the proportion of pane’s vertical (row) size.

The sizes work like this:

  • If you are on a pane that has only one pane of its side (or above/below): 0.3 means the the pane you are on occupies 30 percent of the space in respect to the whole space.
  • If you are on the middle pane: 0.2, 0.9 means the left (or top) most pane gets 20 percent, the right one gets 90 percent and you get the rest.

In the first point by whole space I mean if you have three panes and you are on the first one, it accounts the percentage as if there is only two, and it pushes the other panes to make room.

A tip: You can make more Views Into a File and put them side by side in order to work on different portion of the file and navigate through the panes as opposed to jumping up and down.

Origami has a concept of saving layouts. You also can create a layout and save the workspace. Either one works, but I prefer to save the layout.

Now you can get rid of the sidebar and enjoy more space.

Changing Some Settings

I found these settings to be useful:

{"bold_folder_labels": true,"close_windows_when_empty": true,"detect_slow_plugins": false,"enable_tab_scrolling": false,"ensure_newline_at_eof_on_save": true,"fade_fold_buttons": false,"font_face": "Inconsolata-g for Powerline","font_options":["subpixel_antialias","gray_antialias","directwrite"],"font_size": 11,"line_padding_bottom": 3,"line_padding_top": 3,"margin": 0,"caret_extra_bottom": 0,"caret_extra_top": 0,"caret_extra_width": 1,"caret_style": "wide","tab_size": 4,"spell_check": true,"dictionary": "Packages/Language - English/en_GB.dic","file_exclude_patterns":["*.sqlite3","*.exe","*.pyc","*.pyo","*.dia"],"folder_exclude_patterns":[".svn",".git",".gitignore",".hg","CVS","_build","dist","build","site"],"highlight_line": true,"highlight_modified_tabs": false,"indent_guide_options":["draw_active"],"match_brackets_angle": true,"material_theme_accent_orange": true,"material_theme_contrast_mode": true,"material_theme_small_statusbar": true,"material_theme_small_tab": true,"material_theme_tabs_autowidth": true,"origami_auto_close_empty_panes": true,"save_on_focus_lost": false,"shift_tab_unindent": false,"show_encoding": true,"show_line_endings": true,"show_tab_close_buttons": true,"theme": "Material-Theme-Darker.sublime-theme","translate_tabs_to_spaces": true,"trim_trailing_white_space_on_save": true,"use_tab_stops": true,"word_wrap": "false"}

Notice the file_exclude_patterns and folder_exclude_patterns are also in project settings, when you set it here it applies it to every projects you have. I have excluded .git because I don’t want ST3 to search in those files when I do ctrl+shift+f to search in everything.

Commands

Create a file by any name and sublime-command extension. Like so: arsham.sublime-command and add this to the file:

[{"caption": "Open Mouse Settings", "command": "open_file", "args": {"file": "${packages}/User/Default (Linux).sublime-mousemap"}},]

Then invoke the Command Palette and type in Open Mouse Settings . It will open your mouse map file (I have mentioned this earlier in this article). There is a wide range of commands you can do. In fact, I would like you to do an experiment. Open the Console Panel by hitting ctrl+` then type this in there:

sublime.log_commands(True)

Without closing the console, do something to sublime. Like toggling the SideBar. The short key is ctrl+k ctrl+b . You can see in the console it says:

command: toggle_side_bar

Now you know the command name, you can add this to your commands:

{"caption": "Toggle My sidebar please", "command": "toggle_side_bar"}

And invoke it with command palette. Go ahead and try a few more!

Here are some useful commands:

{"caption": "Reveal File In SideBar", "command": "reveal_in_side_bar"},{"caption": "Open Mouse Settings", "command": "open_file", "args": {"file": "${packages}/User/Default (Linux).sublime-mousemap"}},{"caption": "Open Project", "command": "prompt_open_project_or_workspace"},{"caption": "Fold Comments", "command": "fold_comments"},{"caption": "Unfold Comments", "command": "unfold_comments"},{"caption": "Fold One", "command": "fold_by_level", "args": {"level": 1}},{"caption": "Fold Two", "command": "fold_by_level", "args": {"level": 2}},{"caption": "Fold Three", "command": "fold_by_level", "args": {"level": 3}},{"caption": "Fold Four", "command": "fold_by_level", "args": {"level": 4}},{"caption": "Fold Five", "command": "fold_by_level", "args": {"level": 5}},{"caption": "Fold Six", "command": "fold_by_level", "args": {"level": 6}},{"caption": "Fold Seven", "command": "fold_by_level", "args": {"level": 7}},{"caption": "Fold Eight", "command": "fold_by_level", "args": {"level": 8}},{"caption": "Fold Nine", "command": "fold_by_level", "args": {"level": 9}},

Here are some useful key bindings:

{ "keys": ["super+a"], "command": "alignment" },{ "keys": ["alt+left"], "command": "jump_back" },{ "keys": ["alt+right"], "command": "jump_forward" },{ "keys": ["ctrl+0"], "command": "reset_font_size" },

Please let me know in the comments if you have any suggestions how to improve this article, thanks!

Conclusion

Sublime Text 3 is really fast and comes with a lot of functionalities. When extended with plugins can be the best editor around. Please try to use your keyboard and rely less on mouse navigations.

Enjoy!


Published by HackerNoon on 2017/01/07