Learn How to Use Sublime Text: A Quick Overview
Sublime Text is one of the most popular text editors in the world. It’s jam-packed with powerful features like multi-line editing, build systems for dozens of programming languages, regex find and replace, a Python API for developing plugins, and more.
Best of all, it’s cross-platform (Mac, Windows, and Linux), and it’s distributed as “shareware,” which means it’s free to use with the occasional purchase pop-up.
In this article, you’ll learn how to use Sublime Text to fulfill all your text and code editing needs!
What Is Sublime Text?
Sublime Text bills itself as a “sophisticated text editor for code, markup, and prose.” Originally released over a decade ago in January 2008, Sublime Text is now in its fourth major version and supports Mac, Windows, and Linux.
At its core, Sublime Text is akin to a Swiss Army knife that can be applied to any use case or problem involving manipulating Text.
At first glance, Sublime Text may appear to be a text editor that’s only useful to developers. While it is a great tool for developers, it’s also a powerful app for writers and bloggers.
Before we dive into all the features and capabilities of Sublime Text, let’s quickly walk through a few scenarios where Sublime Text may be useful.
Regex Find and Replace
Regex, short for regular expression, is a syntax for specifying search patterns. Regex is often used to locate similar (but different) text strings for text editing.
For example, if you wanted to strip all HTML tags from a document, it would be very time-intensive to search for each tag to delete (e.g. <h1>
, <p>
, <span>
, etc.).
Instead, you can perform the search with a single regex pattern. In this case, the regex pattern [a-zA-Z0-9]
can be used to find all the HTML tags in a document.
Performing a regex find and replace is very simple in Sublime Text. In the menu bar, click Find > Find in Files. Next, enable regex mode in the find and replace menu, specify the regex pattern in the “Find” field, select <current file>
, and click Find or Replace depending on what you need to accomplish.
Quickly Run Code
Unlike traditional text editors, Sublime Text lets you run code directly within the app. This is especially useful for simpler projects like small Bash or Python scripts.
For example, if you’re writing a simple Python script to scrape data from a list of URLs, setting up a separate Terminal to debug code is less convenient than running the script directly in Sublime Text.
To run code in Sublime Text, go to Tools > Build System, and select the language for your code (Sublime comes with support for various languages like Python, Ruby, Bash, and more). Next, press Cmd+B on Mac or Ctrl+B on Windows to run your code.
Multi-Line Editing
There are all kinds of situations where you may need to edit multiple lines in a text document simultaneously. Imagine you have a list of domains, and you need to prepend http://
to each line. Sure, you can go line by line, but that could potentially take a long time.
With Sublime Text, you can select all the lines you want to edit, press Shift+Cmd+L, and edit every line simultaneously!
As you can see, while Sublime Text has advanced developer-oriented features built-in, there are also a variety of powerful tools like regex support and multi-line editing that are undoubtedly useful for non-developers as well.
Now that you have a general understanding of what Sublime Text can do, let’s take a deeper look and learn more about the app.
Text Snippets
Perhaps the most powerful feature (especially for coders) that Sublime Text has is text snippets.
We all know that writing code can be cumbersome sometimes. Sublime Text Snippets provide a quick and easy way to insert blocks of text that will show up repeatedly in any project.
What makes these text snippets even better is that they are effortless to understand and pretty straightforward to write. This tool helps developers save time and eliminate many errors while developing.
Type the “trigger” word and press the tab button to start a snippet.
How to Download Sublime Text
Sublime Text is available from the official Sublime Text website as a free download. With that said, Sublime Text is technically not “freeware.” Instead, Sublime Text is a “shareware” app, which means it can be downloaded for free, but there may be some feature limitations after a period.
In the case of Sublime Text, the app will continue working indefinitely, but you’ll occasionally see a pop-up with details on how to purchase the app.
If you’re interested in purchasing Sublime Text, you can get a personal license for $99, or business licenses starting at $65/seat/year. While a paid license doesn’t unlock any additional core functionality, you do get access to the following perks:
- No purchase reminder pop-ups
- Access to development versions of Sublime Text
- In-app update notifications
Sublime Text 101 – The Basics
Since Sublime Text is such a jam-packed app in terms of functionality, we’ll discuss essential features and workflows for two subsets of users – writers and developers. But first, let’s establish a core understanding of Sublime Text before branching off into user-specific items.
How to Customize Sublime Text Settings
Unlike other apps with graphical settings menus, the Sublime Text settings are entirely text-based. To view your Sublime Text settings, go to Sublime Text > Preferences, and click Settings. You should then see a document like this:
This settings document may look daunting at first (especially if you’re not used to working with developer-oriented tools), but we’ll help you make sense of everything now!
Sublime Text’s settings are stored in JSON format. JSON is an industry-standard format for storing key-value information, so you may have seen it used somewhere else before. JSON stores information into key-value arrays like so:
{
“color”: “blue”,
“type”: “sedan”,
“seats”: 5,
}
The array above can be used to describe the properties of a car – in this case, a blue sedan with five seats. Similarly, a JSON array can specify settings for an application, which is precisely what Sublime Text does.
Let’s get back to the Sublime Text settings file. As you can see in the screenshot above, the settings file is presented as two JSON arrays. The array on the left contains Sublime Text’s default settings, while the one on the right includes custom user settings.
In general, you should never change the default settings directly. Instead, you can override default settings with custom settings – this allows you to revert to the default settings if something goes wrong.
So, how would you go about changing a few default settings? Let’s say you want to make the changes below:
"font_size": 10
to"font_size": 20
"margin": 4
to"margin": 6
"line_numbers": true
to"line_numbers": false
To make these changes, add each element to the custom user settings document in valid JSON format like so (if you have existing custom settings, add each setting without creating a new array):
{
"font_size": 20,
"margin": 6,
"line_numbers": false,
}
If you’re unsure whether you formatted the settings correctly, you can use an online tool like JSONLint to validate your JSON array. After you’ve specified the settings, save the file, and you’re all set!
Project and File Management in Sublime Text
When working on a project, whether a series of blog posts or source code for a web application, it’s common for your files to be organized within a project folder. Sublime Text considers and provides a functional graphical interface for managing files and directories.
Let’s say you have a folder named “my-sublime-text-project” like the one in the screenshot below. If you drag and drop this folder into Sublime Text, you’ll be able to create new files and folders directly within Sublime Text.
As you can see, the “my-sublime-text-project” folder can be seen on the left-hand side of the Sublime Text window under “Folders.”
Right-clicking on the project folder brings up a sub-menu that lets you create new files, rename files, create and delete folders, and more. Sublime Text’s built-in file management features removes the need for an external tool like Finder to perform basic file management tasks.
Tired of subpar level 1 WordPress hosting support without the answers? Try our world-class support team! Check out our plans
In Sublime Text, a project refers to a collection of imported files and folders (e.g. the “my-sublime-text-project” folder we imported earlier. If you click Project in the menu bar, you’ll see there are options such as “Open Project,” “Switch Project,” and “Save Project As.” However, there is no option to create a new project.
This is because Sublime Text projects are implicitly created when you create a new file and import a folder. In the example above, we can click Project in the menu bar and click Save Project As to save the project.
Sublime Text for Writers
Highlight File Management
Highlight how the file management and project management feature can organize content. For example, an author could create a file for each chapter in a book, while a blogger could create different folders for different categories of posts.
Powerful Search Engine and Replace
Sublime Text has a powerful search and replace implementation. Not only does it support regex, but you can also specify files and folders to search through. For example, if an author wanted to change the name of a character in a story, they could specify the search folder and run the search on all the contents of the folder.
Very Extensible
Sublime Text is extensible, and its MarkdownEditing package is a great tool for writers who use Markdown syntax.
Sublime Text for Developers
Rich Plugin Ecosystem
Sublime Text has a rich plugin ecosystem that can be accessed via the built-in package manager. Developers can install plugins to improve their workflow. For example, the Formatter plugin includes formatting rules for HTML, CSS, JS, Python, and other languages.
The plugin can be configured to automatically format source code files, which helps to keep code neat and standardized in terms of formatting.
A couple more must-have plugins to consider include Package Control (needed for installing plugins) and Emmet.
Multi-Line Editing
Sublime Text offers multi-line editing, which can be accessed by holding down Command on Mac (Ctrl on Windows) and using the mouse to select multiple lines. After multiple lines are selected, you can edit all lines at once, and multi-line copy/paste is even supported.
Split Window Support
Sublime Text supports split windows to view and edit multiple files simultaneously. This can be useful when referring to a different file while working on a project.
Support For Build Systems
Sublime Text ships with support for build systems. Build systems let you run code directly in the Sublime Text editor’s terminal without the need for an external terminal.
For example, you could create a build system to run a Python program and another build system to run a Go program. When developing an application, you can select a build system and use a shortcut to run the program directly from Sublime Text.
More Customizability With Themes
You can enhance your coding experience even more by downloading a Sublime Text theme. Most of them come bundled with a variety of color schemes already.
The difference between themes and color schemes for Sublime Text is that a theme decorates the core UI elements, like side-pane, tabs, menus, and more, while color schemes are responsible for syntax-highlighting.
Some of the best themes to check out include:
Summary
Sublime Text is one of the most popular code editors out there today. Rightfully so, it provides both writers and developers with a ton of tools to use.
There’s nothing more satisfying than finding the perfect code editor. If you have never tried Sublime Text, it is worth a look.
Are you currently using Sublime Text? Do you prefer it over other code editors? Let us know in the comment section below.
The post Learn How to Use Sublime Text: A Quick Overview appeared first on Kinsta®.
共有 0 条评论