Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Sublime Text encoding


May 24, 2021 Sublime Text Use the manual


Table of contents


Coding (Coding)

Good editors make coding easier, so Sublime Text provides a range of features to improve development efficiency.

Good Practices

Good code should be standard, so Google has its Code Guidelines for every major language. I myself normalize my code with the following settings.

// 设置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 snippets, which Tab generates by entering the snippet name.

Sublime Text encoding

You can install third-party snipppppping with Package Control, or you can create your own.

Formatting

Sublime Text Basic manual formatting operations include: Ctrl + [ s indentation to the left, Ctrl + ] to the right, Ctrl + Shift + V paste code in the current indentation (very useful).

In addition to manual formatting, we can also automatically indent and intelligently align by installing plug-ins:

  • HTMLBeautify: Format HTML.
  • AutoPEP8: Format the Python code.
  • Alignment: Smart alignment.

Auto Finish

Sublime Text supports a certain amount of auto-completion, which is automatically completed by Tab.

Sublime Text encoding

Brackets

When you write code, you run into a lot of brackets, Ctrl + M you can quickly switch between the start and end brackets, Ctrl + Shift + M can quickly select what's in parentheses, and you can use Ctrl + Shift + J languages such as Python.

Sublime Text encoding

In addition, I use BracketHighlighter to highlight the pairing brackets and the area where the current cursor is located, as follows:

Sublime Text encoding

Command Line

Despite the Python console, sublime Text's console only supports single-line input, which is inconvenient, Sublime​REPL for some coding experiments.

Sublime Text encoding

Others (Miscellaneous)

Despite my attempts to include as many Sublime Text practical skills as possible in this article, due to space and my personal experience, this article is still missing, and we welcome to point out the errors and omissions in this article in our comments.

Here are some features that might work but are rarely used:

  • Macro: Sublime Text supports recording macros, but I don't really see how useful macros are.
  • Other Platforms: This article only describes the use of Sublime Text on Windows platforms, but the way Sublime Text is used on Linux and OS X is not much different from Windows, but only on shortcuts, refer to Windows/Linux shortcuts and OS X shortcuts.
  • Projects: Sublime Text supports simple project management, but I generally only use folders.
  • Vim mode: Sublime Text brings its own Vim mode.
  • Build: Sublime Text can be configured to be source-built.
  • Debug: By installing plug-ins, Sublime Text can debug code.

Shortcuts Cheatsheet

I've put the Sublime Text that appears in this article here by type for review.

General

  • The cursor ←→ up and down, pay attention not to KJHL!
  • Alt: Call up the menu
  • Ctrl s Shift s P: Call Out Command Palette
  • Ctrl s': Call up the console

Editing

  • Ctrl and Enter: Add a new line below the current line and jump to the line
  • Ctrl s Shift s Enter: Add a row above the current line and jump to that line
  • Ctrl ←/→: Move word for word
  • Ctrl and Shift ←/→ word-by-word selection
  • Ctrl s
  • Ctrl and Shift move the current line

Select

  • Ctrl s D: Select the word in which the current cursor is located and highlight all the places where the word appears, again Ctrl s D select the next position where the word appears, skip using Ctrl plus K, fall back with Ctrl plus U, and exit multiple editing with Esc
  • Ctrl s Shift s L: Break up the currently selected area
  • Ctrl and J: Merge the currently selected areas into one row
  • Ctrl and M: Switch between the opening and ending brackets
  • Ctrl s Shift s M: Quickly select what's in parentheses
  • Ctrl s Shift s J: Quickly select content that is indented with
  • Ctrl, Shift, Space: Quickly select the contents of the current scope

Find and Replace (Finding and Replacing)

  • F3: Jump to the next location of the current keyword
  • Shift s F3: Jump to the last position of the current keyword
  • Alt s F3: Check all locations where the current keyword appears
  • Ctrl and F/H: Standard Lookup/Replacement, after which:
    • Alt-C: Switch case-sensitive mode
    • Alt and W: Switch the whole word matching mode
    • Alt and R: Switch regular matching mode
    • Ctrl s Shift s H: Replace the current keyword
    • Ctrl, Alt, Enter: Replace all keyword matches
  • Ctrl s Shift s F: Multi-file search and replacement

Jump

  • Ctrl s P: Jump to the specified file, enter the file name can: s symbol jump: enter@symbol jump to the symbol symbol where the keyword jump: enter the s keyword jump to keyword location: line number jump: enter: 12 jump to the 12th line of the file.
  • Ctrl and R: Jump to the specified symbol
  • Ctrl and G: Jump to the specified line number

Window

  • Ctrl s Shift s N: Create a new window
  • Ctrl s N: Create a new label in the current window
  • Ctrl s W: Close the current label, which closes when there are no labels in the window
  • Ctrl s Shift s T: Restore the label that just closed

Screen

  • F11: Switch normal full screen
  • Shift s F11: Switch without interference with full screen
  • Alt s Shift s 2: Split left and right
  • Alt s Shift s 8: Split up and down the screen
  • Alt s Shift s 5: Split the screen up and down left and right
  • After splitping the screen, jump to the specified screen using the Ctrl plus number keys, and use the Ctrl plus Shift plus number keys to move the current screen to the specified screen