Sublime Text's most detailed tutorial

Today I will share with you the knowledge of the most detailed tutorial of Sublime Text.

foreword

Sublime Text is a cross-platform code editor (Code Editor). From the original Sublime Text 1.0 to the current Sublime Text 3.0, Sublime Text has evolved from an unknown editor to the GUI editor of choice for almost all platforms. . But such an excellent editor does not have a reliable Chinese tutorial, so I try to make up for this defect through this article.

1 Installation

The official website of Sublime Text provides downloads for each system and version of Sublime Text. Currently, the latest version of Sublime Text is Sublime Text 3. Here we take the Windows version of Sublime Text installation as an example.

Note that when installing, check Add to explorer context menu, so that when you right-click a file, you can directly use Sublime Text to open it.
Add insert image description here
Sublime Text to environment variables

Run sysdm.cpl using Win + R to open System Properties.
insert image description here
Then select "Environment Variables" in the "Advanced" tab, edit "Path", and increase the installation directory of Sublime Text (eg D:\Program Files\Sublime Text 3).
insert image description here
Then you can use the subl command to use Sublime Text directly in the command line:

subl file    :: 使用 Sublime Text 打开 file 文件
subl folder  :: 使用 Sublime Text 打开 folder 文件夹
subl .       :: 使用 Sublime Text 当前文件夹

2 Install Package Control

As mentioned earlier, Sublime Text supports a large number of plug-ins. How to find and manage these plug-ins has become a problem. Package Control appeared to solve this problem. With it, we can easily browse, install and uninstall the plug-ins in Sublime Text. .

Enter the official website of Package Control, which has a detailed installation tutorial. Package Control supports Sublime Text 2 and 3, this article only gives the installation process of 3:

1. Use Ctrl + ` to open the Sublime Text console.
2. Paste the following code into the console:

import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

3. Wait for the Package Control installation to complete. Then use Ctrl + Shift + P to open the command board, enter PC and Package Control should appear:
insert image description here
After successfully installing Package Control, we can easily install various plug-ins using Sublime Text:
insert image description here
Purchase (Purchase)

Sublime Text is a paid closed source software, which has become the reason for me to support Sublime Text to a certain extent (the software reliability in my mind: free open source << free closed source < paid open source < paid closed source): buy here .

However, you can use it "normally" without purchasing Sublime Text, but Sublime Text will pop up a dialog box from time to time to remind you to purchase, and there will be a very low-key (UNREGISTERED) in the window. (Under high-frequency operation, it is usually reminded once every 20 minutes, which is very kind in my opinion)
insert image description here

3 Overview (Tour)

Basic Concepts

The interface of Sublime Text is as follows:
insert image description here

1. Tab: Needs no introduction.
2. Editing Area: No introduction needed.
3. Side Bar: Contains the currently opened files and folder views.
4. Thumbnail (Minimap): As the name suggests.
5. Command Palette: Sublime Text's operation center, which allows us to basically operate without the mouse and menu bar.
6. Console (Console): use Ctrl + ` to call out, it is not only a standard Python REPL, but also can directly configure Sublime Text.
7. Status Bar (Status Bar): Display information such as the current line number, current language, and Tab format.

Configuration (Settings)
Unlike editors in other GUI environments, Sublime Text does not have a dedicated configuration interface. On the contrary, Sublime Text uses JSON configuration files, for example:

{
    
    
  "font_size": 12,
  "highlight_line": true,
}

will adjust the default font size to 12 and highlight the current line.

The introduction of JSON configuration files simplifies the interface of Sublime Text, but it also makes the configuration more complicated. Generally, I will go here to check the available Sublime Text configurations.

Editing (Editing)
Sublime Text's editing is very user-friendly - it is not as anti-human as Vim (although I also use Vim, but I still have to say that Vim's shortcut key settings are not as good as metabolites), a small number of shortcut keys Can complete most editing tasks.

Basic Editing (Basic Editing)
↑↓←→ is ↑↓←→, not KJHL, (yes, I’m just complaining about Vim, it’s better to set it to WSAD), paste, cut and copy are consistent with the system.

Ctrl + Enter adds a new line below the current line and jumps to it; Ctrl + Shift + Enter adds a line above the current line and jumps to it.
insert image description here
Ctrl + ←/→ moves word by word, and correspondingly, Ctrl + Shift + ←/→ selects word by word.
insert image description here
Ctrl + ↑/↓ moves the current display area, Ctrl + Shift + ↑/↓ moves the current line.
insert image description here
Selecting

One of the highlights of Sublime Text is its support for multiple selections - select multiple areas at the same time, and then edit them at the same time.

Ctrl + D selects the word where the cursor is currently located and highlights all occurrences of the word, Ctrl + D again selects the next occurrence of the word, in the process of multiple word selection, use Ctrl + K to skip, use Ctrl + U to go back, use Esc to exit multi-edit.

A big use case for multi-word selection is renaming - thus making the code cleaner. Although Sublime Text cannot automatically rename like IDEs (such as Eclipse), we can perform intuitive and convenient renaming through multiple word selection + multiple editing: sometimes we need to edit all
insert image description here
lines in an area at the same time, Ctrl + Shift + L can disperse the currently selected area, and then edit it at the same time:
insert image description here
if there is dispersal, there will be a merge, Ctrl + J can merge the currently selected area into one line:
insert image description here
Find&Replace (Finding&Replacing)
Sublime Text provides a powerful search (and Replace) function, in order to provide a clear introduction, I divided the search function of Sublime Text into three types: quick search, standard search and multi-file search.

Quick Find & Replace
In most cases, we need to find other places where a keyword appears in the text. At this time, there is no need to re-enter the keyword and search again. We only need to use Shift + ←/→ or Ctrl + D Select the keyword, then F3 jumps to its next occurrence, Shift + F3 jumps to its previous occurrence, and you can also use Alt + F3 to select all its occurrences (multiple edits can be performed later, that is, quick replacement) .
insert image description here
Standard Find & Replace
Another common usage scenario is to search for a keyword that is known but not in the current display area. At this time, you can use Ctrl + F to bring up the search box to search:
insert image description here
and use Ctrl + H to replace:
insert image description here
keyword Find & Replace
For ordinary users, regular keyword search can meet their needs: after entering a keyword in the search box, Enter jumps to the next position of the keyword's current cursor, Shift + Enter jumps to the previous position, Alt + Enter Selects all occurrences of it (again, a quick replace can follow).

Sublime Text's search has different modes: Alt + C to switch case-sensitive (Case-sensitive) mode, Alt + W to switch whole word matching (Whole matching) mode, in addition Sublime Text also supports searching within the selected range ( Search in selection), this function does not have a corresponding shortcut key, but it can be automatically enabled through the following configuration items.

"auto_find_in_selection": true

In this way, the range search will be automatically enabled when the text is selected. With this function, Local Renaming (Local Renaming) becomes very convenient: use Ctrl + H to perform standard
insert image description here
replacement, and after entering the replacement content, use Ctrl + Shift + H replaces the current keyword, Ctrl + Alt + Enter replaces all matching keywords.

Regular expression find & replace
Regular expression is a very powerful text search & replace tool, use Alt + R in Sublime Text to switch the regular matching mode on/off. Sublime Text uses the Perl regular expression style in Boost.

For reasons of space, this article will not introduce regular expressions in detail. Mastering Regex (Chinese translation: proficient in regular expressions) introduces the principles of regular expressions and the use of each language in detail. In addition, there are a large number of excellent tutorials on regular expressions on the Internet ("30-minute regular expression tutorial" and MSDN regular expression tutorial.aspx)), as well as online testing tools (regexpal and regexer).

Multi-file search & replace
Use Ctrl + Shift + F to open multi-file search & replace (note that this shortcut key conflicts with the shortcut key for switching between Simplified and Traditional Chinese in the Sogou input method): multi-file search
insert image description here
& replace defaults to the currently opened file and folder To search/replace, we can also specify files/folders to search/replace.

Jumping (Jumping)
Sublime Text provides a powerful jump function that allows us to seamlessly switch between different files/methods/functions. As far as my experience is concerned, there is currently no editor that can surpass Sublime Text in this regard.

Jump to file
Ctrl + P will list the currently opened files (or files in the current folder), enter the file name and enter to jump to the file.

It should be noted that Sublime Text uses fuzzy string matching (Fuzzy String Matching), which means that you can match by the prefix, initial letter or part of the file name: for example, EIS, Eclip and Stupid can all be matched EclipseIsStupid.java.
insert image description here
Jumping to Symbols
Despite being a text editor, Sublime Text is able to index code symbols to some degree. Ctrl + R will list the symbols in the current file (such as class names and function names, but you can't drill down to variable names), enter the symbol name Enter to jump there.

In addition, you can use F12 to quickly jump to the definition of the symbol where the current cursor is (Jump to Definition).
insert image description here
What's more interesting is that for Markdown, Ctrl + R will list its outline, which is very practical.
insert image description here
Jump to a certain line
Ctrl + G and then enter the line number to jump to the specified line:
insert image description here
combined jump
After Ctrl + P matches the file, we can make subsequent input to jump to a more precise location:

1.@ symbol jump: enter @symbol to jump to the position where the symbol symbol is located
2.# keyword jump: enter #keyword to jump to the position where the keyword is located
3.: line number jump: enter: 12 to jump to Line 12 of the file.
insert image description here
So Sublime Text calls Ctrl + P "Go To Anything". This feature is so easy to use that I don't think any other editor can surpass it.

Problems with Chinese input methods
From the first version of Sublime Text (1.0) to the present (3.0 3065), Chinese input methods (including Japanese input methods) have a problem: the input box does not follow.
insert image description here
At present, the official has not fixed this bug. The solution is to install the IMESupport plug-in, and then restart Sublime Text to solve the problem.
insert image description here
Folders (Folders)
Sublime Text supports editing in folders, which is especially useful when editing code under a folder. Open Folder under File:

You will find that there is an extra sidebar on the right. This sidebar lists the files of the currently opened files and folders. Use Ctrl + K, Ctrl + B to show or hide the sidebar, and use Ctrl + P to quickly jump to the folder. files in .

Window & Tabs (Windows & Tabs)
Sublime Text is a multi-window multi-tab editor: we can open multiple Sublime Text windows, or open multiple tabs in one Sublime Text window.

Window (Window)
Use Ctrl + Shift + N to create a new window (this shortcut key conflicts with the Sogou input method shortcut key again, and I personally recommend disabling all Sogou input method shortcut keys).

When there are no tabs in the window, use Ctrl + W to close the window.

Tab (Tab)
Use Ctrl + N to create a new tab in the current window, Ctrl + W to close the current tab, and Ctrl + Shift + T to restore the just closed tab.

We often open multiple windows when editing code, so split screen is very important. Alt + Shift + 2 to split the screen left and right, Alt + Shift + 8 to split the screen up and down, and Alt + Shift + 5 to split the screen up, down, left, and right (that is, to divide into four screens).
insert image description here
After splitting the screen, use Ctrl + number keys to jump to the specified screen, and use Ctrl + Shift + number keys to move the current screen to the specified screen. For example, Ctrl + 1 will jump to 1 screen, and Ctrl + Shift + 2 will move the current screen to 2 screens.

Full Screen (Full Screen)
Sublime Text has two full screen modes: normal full screen and distraction-free full screen.

Personally, it is strongly recommended to close the menu bar (Toggle Menu) before opening the full screen, otherwise the full screen effect will be greatly reduced.

F11 switch normal full screen:
insert image description here
Shift + F11 switch non-interference full screen:
insert image description here
Styles (Styles)
style is very important for any software, and so is the editor, especially the editor in the GUI environment. As a programmer, I want my editor to be concise and individual.

Notepad++ default interface
insert image description here
Sublime Text default interface
insert image description here
So after using Sublime Text, I immediately uninstalled Notepad++.

The style that comes with Sublime Text is my favorite dark style (it can also be adjusted to light), and the default theme is Monokai Bright. The combination of the two is already very good, but we can do better: Next I It will show how to make Sublime Text more Stylish by setting preferences and adding custom styles/themes.

4 Some settings (Miscellaneous Settings)

Below are the settings I personally use.

// 设置Sans-serif(无衬线)等宽字体,以便阅读
"font_face": "YaHei Consolas Hybrid",
"font_size": 12,
// 使光标闪动更加柔和
"caret_style": "phase",
// 高亮当前行
"highlight_line": true,
// 高亮有修改的标签
"highlight_modified_tabs": true,

The effect after setting is as follows:
insert image description here
Themes (Themes)
Sublime Text has a large number of third-party themes:
https://sublime.wbond.net/browse/labels/theme , here I give a few themes that I feel good about:
Soda Light
insert image description here
Soda Dark
insert image description here
Nexus
insert image description here
Flatland
insert image description here
Spacegray Light
insert image description here
Spacegray Dark
insert image description here
color matching (Color)
colorsublime contains a large number of Sublime Text color schemes, and supports online preview. The installation tutorial of the color scheme is here, so I won't go into details.

I personally use the Nexus theme and the Flatland Dark color scheme, the configuration is as follows:

"theme": "Nexus.sublime-theme",
"color_scheme": "Packages/Theme - Flatland/Flatland Dark.tmTheme",

The effect is as follows:
insert image description here
Coding (Coding)
Excellent editors make coding easier, so Sublime Text provides a series of functions to improve development efficiency.

Good Practices (Good Practices)
Good code should be standardized, so Google has set up its Code Style Guideline for each mainstream language. I use the following settings to normalize my own code.

// 设置tab的大小为2
"tab_size": 2,
// 使用空格代替tab
"translate_tabs_to_spaces": true,
// 添加行宽标尺
"rulers": [80, 100],
// 显示空白字符
"draw_white_space": "all",
// 保存时自动去除行末空白
"trim_trailing_white_space_on_save": true,
// 保存时自动增加文件末尾换行
"ensure_newline_at_eof_on_save": true,

Code Snippets
Sublime Text supports Code Snippet. After entering the name of the code segment, press Tab to generate the code segment.
insert image description here
You can install third-party code snippets through Package Control, or create code snippets yourself, refer to here.

Formatting (Formatting)
Sublime Text's basic manual formatting operations include: Ctrl + [ to indent left, Ctrl + ] to indent right, and Ctrl + Shift + V can paste code with the current indentation (very useful).

In addition to manual formatting, we can also achieve automatic indentation and smart alignment by installing plug-ins:
1.HTMLBeautify: Format HTML.
2. AutoPEP8: Format Python code.
3.Alignment: Perform intelligent alignment.

Auto Completion (Auto Completion)
Sublime Text supports certain auto completion, press Tab to complete automatically.
insert image description here
Brackets (Brackets)
When writing code, you will encounter a lot of brackets. Use Ctrl + M to quickly switch between the start bracket and the end bracket. Ctrl + Shift + M can quickly select the content between the brackets. For indented languages (such as Python) you can use Ctrl + Shift + J .
insert image description here
In addition, I use the BracketHighlighter plug-in to highlight the paired brackets and the area where the current cursor is located. The effect is as follows: Although
insert image description here
the command line (Command Line)
provides a Python console, the Sublime Text console only supports single-line input, which is very inconvenient, so I use SublimeREPL for some coding experiments (Experiments).
insert image description here
Miscellaneous

Although I try to include as many Sublime Text practical skills as possible in this article, due to space limitations and my personal experience, this article still has some omissions. You are welcome to point out the errors and omissions in this article in the comments.

Here are some features that may be useful but I rarely use them:
1. Macro: Sublime Text supports recording macros, but I haven't found much use for macros in actual work.

2. Other Platforms (Other Platforms): This article only introduces the use of Sublime Text on the Windows platform, but the usage of Sublime Text on Linux and OS X is not much different from that of Windows, except for the shortcut keys. Please refer to Windows /Linux shortcuts and OS X shortcuts.

3. Projects: Sublime Text supports simple project management, but I generally only use folders.

4. Vim mode (Vintage): Sublime Text comes with Vim mode.

5. Build (Build): Through configuration, Sublime Text can build source code.

6. Debug (Debug): By installing the plug-in, Sublime Text can debug the code.

Shortcuts Cheatsheet
I organize the Sublime Text that appears in this article according to its type here for easy reference.

General (General)
1. ↑↓←→: Move the cursor up, down, left, and right, pay attention to whether it is KJHL!
2.Alt: Bring up the menu
3.Ctrl + Shift + P: Bring up the Command Palette
4.Ctrl + `: Bring up the console

Editing (Editing)
1.Ctrl + Enter: add a new line below the current line and jump to this line
2.Ctrl + Shift + Enter: add a line above the current line and jump to this line
3.Ctrl + ←/→: proceed Move word by word
4.Ctrl + Shift + ←/→ select word by word
5.Ctrl + ↑/↓ move the current display area
6.Ctrl + Shift + ↑/↓ move the current line

Selection (Selecting)
1.Ctrl + D: Select the word where the current cursor is and highlight all occurrences of the word, Ctrl + D again to select the next occurrence of the word, in the process of multiple word selection, use Ctrl + K to skip, use Ctrl + U to go back, and use Esc to exit multiple
editing : Switch between the start bracket and the end bracket 5.Ctrl + Shift + M: Quickly select the content between the brackets 6.Ctrl + Shift + J: Quickly select the same indented content 7.Ctrl + Shift + Space: Quickly select the current Scope content




Find & Replace (Finding&Replacing)
1.F3: Jump to the next position of the current keyword
2.Shift + F3: Jump to the previous position of the current keyword
3.Alt + F3: Select all positions where the current keyword appears
4.Ctrl + F/H: Perform standard find/replace, after:
5.Alt + C: Toggle case-sensitive (Case-sensitive) mode
6.Alt + W: Toggle whole word matching (Whole matching) mode
7.Alt + R: Toggle Regular matching (Regex matching) mode
8.Ctrl + Shift + H: Replace the current keyword
9.Ctrl + Alt + Enter: Replace all keyword matches
10.Ctrl + Shift + F: Multi-file search & replace

Jumping (Jumping)
1.Ctrl + P: jump to the specified file, after inputting the file name:
2. @ symbol jump: enter @symbol to jump to the position where the symbol symbol is located
3.# keyword jump: enter #keyword Jump to the position where the keyword is located
4.: Line number jump: Enter: 12 to jump to the 12th line of the file.
5.Ctrl + R: Jump to the specified symbol
6.Ctrl + G: Jump to the specified line number

Window (Window)
1.Ctrl + Shift + N: Create a new window
2.Ctrl + N: Create a new tab in the current window
3.Ctrl + W: Close the current tab, when there is no tab in the window, the window will be closed
4 .Ctrl+Shift+T: Restores just closed tab

Screen
1.F11: switch to normal full screen
2.Shift + F11: switch to full screen without interference
3.Alt + Shift + 2: perform left and right split screen
4.Alt + Shift + 8: perform up and down split screen
5.Alt + Shift + 5: Split the screen up, down, left, and right
6. After splitting the screen, use Ctrl + number keys to jump to the specified screen, and use Ctrl + Shift + number keys to move the current screen to the specified screen

5 Further Reading

Books (Books)
Mastering Sublime Text: The only book I have read about Sublime Text. The plug-ins introduced in the book are very practical, but the editing skills are not fully introduced.

Instant Sublime Text Starter: Another book on Sublime Text that I haven't read.

Links (Links)
1. Official document: http://www.sublimetext.com/docs/3/
2. Official forum: http://www.sublimetext.com/forum/
3. Sublime Text channel of Stack Overflow: 4 . http://stackoverflow.com/questions/tagged/sublimetext
5. http://stackoverflow.com/questions/tagged/sublimetext2
6. http://stackoverflow.com/questions/tagged/sublimetext3
7. Unofficial documentation: http://sublime-text-unofficial-documentation.readthedocs.org/ is even more comprehensive than the official documentation!
8.Package Control: https://sublime.wbond.net/ A large number of Sublime Text plugins and themes.

Videos

How much have you learned about the most detailed tutorial on Sublime Text? Welcome to comment in the message area!

Guess you like

Origin blog.csdn.net/weixin_45794138/article/details/104038614