subl
Open files or directories in Sublime Text
TLDR
Open the current directory in Sublime Text
Open a file or directory in Sublime Text
Open a file and jump to a specific line number
Open a file or directory in the currently open window
Open a file or directory in a new window
SYNOPSIS
subl [OPTIONS] [FILE|FOLDER[:LINE[:COLUMN]]]...
subl -d <FILE1> <FILE2>
PARAMETERS
-n, --new-window
Opens files or folders in a new Sublime Text window, even if an existing window is open.
-a, --add
Adds folders to the current Sublime Text window. If no window is open, a new one is created and the folders are added to it.
-w, --wait
Waits for the opened files to be closed in Sublime Text before the command returns control to the terminal. Essential for use with Git commit messages or scripting.
-l <line>, --line <line>
Opens the specified file at the given line number. This can also be achieved by using the :LINE suffix with the file path.
-c <column>, --column <column>
Opens the specified file at the given column number. This option requires -l or the :LINE:COLUMN syntax to specify a line number first.
-e <encoding>, --encoding <encoding>
Specifies the character encoding to use when opening the file, e.g., utf-8, latin1.
-p <project>, --project <project>
Loads the specified Sublime Text project file (typically with a .sublime-project extension) into a new or existing window.
-d, --diff
Compares two files side-by-side in a Sublime Text window, highlighting their differences. Requires exactly two file paths as arguments.
--command <command>
Executes a specific Sublime Text internal command. This allows for advanced scripting and automation within the editor, e.g., --command 'save_all' or --command 'build'.
-h, --help
Displays a comprehensive help message outlining all available command-line options and their usage.
-v, --version
Prints the installed Sublime Text version information to the terminal.
DESCRIPTION
The subl command provides a powerful command-line interface for the Sublime Text editor. It allows users to seamlessly open files, folders, and projects directly from their terminal, integrating Sublime Text into their command-line workflows. This utility is particularly useful for quickly accessing and editing code, navigating project structures, or performing operations like diffing files without leaving the shell environment. It enables scripting and automation, making it a versatile tool for developers and power users who prefer a hybrid approach of GUI and CLI interactions. The subl command is typically made available by creating a symbolic link during the Sublime Text installation process, often residing in /usr/local/bin.
CAVEATS
The subl command relies on a symbolic link being correctly established from a directory in your $PATH (e.g., /usr/local/bin) to the Sublime Text executable. If Sublime Text was not installed in a standard way, or if this link was not created (or was removed), the subl command will not be found by your shell. On macOS, this link is conveniently created via the 'Tools -> Install Command Line Tool' menu option within Sublime Text itself. On Linux, it often requires manual creation or is handled by package managers during installation.
SETUP AND CONFIGURATION
To ensure subl is available in your terminal, a symbolic link must point to your Sublime Text installation. For Linux users, a common setup involves: sudo ln -s /opt/sublime_text/sublime_text /usr/local/bin/subl (adjust path as necessary). macOS users can simply open Sublime Text, go to the 'Tools' menu, and select 'Install Command Line Tool'. This will set up the symlink automatically.
INTEGRATION WITH GIT AND SHELL ENVIRONMENTS
The subl command is frequently used to set Sublime Text as the default editor for various command-line tools. For Git, you can configure it globally using: git config --global core.editor 'subl -w'. The -w (wait) option is crucial here, as it forces Git to pause until you save and close the file in Sublime Text. Users often create shell aliases like alias st='subl' in their .bashrc or .zshrc files for quicker access.
HISTORY
Sublime Text first emerged in 2008, quickly gaining popularity for its speed, extensibility, and minimalist interface. From its inception, the command-line tool (subl) has been an integral part of the editor's offering, reflecting its design philosophy of empowering developers through efficient workflows. While the core functionality of opening files and folders has remained consistent, minor enhancements, such as the --diff and --command options, have been introduced in subsequent major versions (Sublime Text 2, 3, and 4) to broaden its utility and deepen its integration with external tools and scripts.