Ora

How do you sort by column in Sublime?

Published in Sublime Text Sorting 2 mins read

To sort by column in Sublime Text, you simply select the desired column of text across multiple lines and then press F9. This action sorts all the affected lines using the content of the selected column as the sorting key.

How to Sort by Column in Sublime Text

Sorting by column in Sublime Text is a powerful feature, especially when dealing with structured or log data where you need to reorder entries based on a specific field. For instance, if you have log data with timestamps that are out of order, you can use this method to quickly sort them to see events in their correct chronological sequence.

Step-by-Step Guide to Column Sorting

Follow these steps to effectively sort your text by a specific column:

  1. Place Your Cursor: Position your cursor at the beginning of the column you wish to sort by. This is the starting point for your column selection.
  2. Initiate Column Selection: To select the column across multiple lines, use the following key combinations:
    • Windows/Linux: Press and hold Alt + Shift, then use the Up or Down arrow keys to extend your selection vertically.
    • macOS: Press and hold Cmd + Shift, then use the Up or Down arrow keys.
    • Alternatively, you can hold down Ctrl (Windows/Linux) or Cmd (macOS) and click at the beginning and end of the desired column range, or drag to select multiple non-contiguous lines, then use Shift + Right Arrow to select the column content.
  3. Confirm Column Selection: Ensure that the column of text you intend to sort by is highlighted across all the relevant lines.
  4. Execute Sort Command: Once your column selection is active, press F9.

The lines where your column selection intersects will immediately be sorted based on the textual content within that specific column.

Understanding Column Sorting in Sublime Text

This method is incredibly useful for a variety of tasks, including:

  • Log File Analysis: Reordering log entries by timestamp, error code, or any other fixed-position field.
  • Data Cleaning: Organizing CSV-like data by a specific field without needing a dedicated spreadsheet application.
  • Code Refactoring: Sorting configuration lists or variable definitions alphabetically by a key, assuming they are aligned in columns.

By utilizing the column selection and the F9 command, Sublime Text provides a quick and intuitive way to manage and reorder your text data effectively.