SubLime Text PackageDev plugin highlighting rule settings

foreword

        As an Android developer, Android Studio's Logcat is the most frequently used to view log files during development, and the latest version of AS's Logcat has been adjusted, and the friendliness has been greatly improved.

But sometimes what we need to see is the log uploaded from the background. At this time, Logcat cannot play a role. Since I use a Mac computer, I use Sublime Text as a tool for daily log viewing. Since the log is very large, Therefore, if the log can be highlighted in color, the efficiency may be improved. I searched the current online solutions, but the writing is not very clear, and I don’t know how to configure the color. The following method is the result of my own testing. Not much nonsense, let's start directly.

Install PackageDev

        PackageDev is a utility that provides syntax highlighting for Sublime Text resource files. In Sublime Text, the main role of the resource file is to configure the Sublime Text text editor in various ways that can be extended, including but not limited to: custom syntax definitions, context menus (and main menus), key bindings, and more. In other words, we can configure our own grammar rules. This plug-in is very powerful, and it is easy to configure log viewing.

Open the command panel of Sublime Text to install the plug-in, and search for PackageDev installation after a while.

Configure grammar rules

Click tools -> Packages -> New Syntax Definition to create a new template file.

The above is our new template file, we modify this template, the modified file is below.

  • name refers to the rules to open the text file in Sublime Text, select it in the lower right corner of Sublime Text. If this attribute is not specified, the file name shall prevail.
  • file_extensions uses this rule to identify text file extensions (xxx.log xxx.logcat).
  • scope is for not knowing what it is for.
  • contexts is mainly for configuration rules in different language environments
  • main Every grammar must define a main context, which is applied at the very beginning of the text.
  • match Use regular expressions to match text. Matches only one line of text at a time.
  • scope The type of coloring assigned to the matched text.
  • captures When regular matching uses non-group captures, corresponding to different captured values, the matched content is colored by group respectively.

The most important thing here is to configure match regular matching rules. Here is a recommended website, Regular Expressions – Tutorial | Cainiao Tutorial. You can follow the grammar rules and test online. Since the background log I use is special, it may not necessarily match. This requires Notice. example:

Statement to be matched: 12-30 05:56:56.556 1844 4619 E CoreBackPreview: xxxxxxxxx

Regular expression: \d{2}(\-|\/|.)\d{1,2}\1\d{1,2}.*(\s{1}W{1}\s{1 })(.*)

After completing the configuration, just save it directly. The file should be stored under /Users/zhuangqing/Library/Application Support/Sublime Text/Packages/User, and Sublime Text will automatically recognize it.

configure color

Click Sublime Text -> Preferences -> Customize Color Scheme to create a custom color scheme.

Add color rules in rules.

Save after configuring the color. Note that Sublime Text may need to be closed and reopened. After reopening, open an android log, pay attention to the file extension, or select Logcat (Android Studio) in the lower right corner.

 

After the configuration is complete, let's take a look at the effect. The current effect is only for demonstration, and more details need to be configured carefully. For more grammar rules, you can read the official document:  Syntax Definitions.

Guess you like

Origin blog.csdn.net/z2008q/article/details/128792754