/sort-lines

An Atom package to sort lines of text

Primary LanguageJavaScriptMIT LicenseMIT

Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our official announcement

Sort Lines Package Build Status

Sorts your lines in Atom. Never gets tired.

sort-lines-demo

Installation

From within Atom: Settings -> Install -> search for "sort-lines" and click "Install" OR

From CLI: apm install sort-lines and restart Atom.

Commands and Keybindings

All of the following commands are under the atom-text-editor selector.

If any lines are selected in the active buffer, the commands operate on the selected lines. Otherwise, the commands operate on all lines in the active buffer.

Command Description Keybinding
sort-lines:sort Sorts the lines (case sensitive) F5
sort-lines:case-insensitive-sort Sorts the lines (case insensitive)
sort-lines:natural Sorts the lines ("natural" order)
sort-lines:by-length Sorts the lines by length
sort-lines:shuffle Sorts the lines in random order
sort-lines:reverse Reverses current order of the lines
sort-lines:unique Removes duplicate lines

Custom keybindings can be added by referencing the above commands. To learn more, visit the Using Atom: Basic Customization or Behind Atom: Keymaps In-Depth sections in the flight manual.

[Optional] Custom sorting combinations

Each command above provides an individual type of sorting operation. If you find yourself frequently performing multiple types of sorts back-to-back, you can optionally define a command to perform all those sorts at once. For example, if you want to perform a case-insensitive reverse sort, you can first run the sort-lines:case-insensitive-sort command followed by the sort-lines:reverse command, or you can define a custom composed command that performs both of these operations for you.

You can define these custom commands in your init file. (You can read more about customizing your init file in the flight manual.) If your init file is named init.coffee, refer to the init.coffee example below. If your init file is named init.js, refer to the init.js example below.

init.coffee example

# Perform a case-insensitive reverse sort of the selected lines (or all lines in
# the file if no lines are selected)
atom.commands.add 'atom-text-editor:not([mini])', 'me:case-insensitive-reverse-sort', ->
  editor = atom.workspace.getActiveTextEditor()
  editorView = atom.views.getView(editor)
  atom.commands.dispatch editorView, 'sort-lines:case-insensitive-sort'
  .then () -> atom.commands.dispatch editorView, 'sort-lines:reverse'

init.js example

// Perform a case-insensitive reverse sort of the selected lines (or all lines
// in the file if no lines are selected)
atom.commands.add('atom-text-editor:not([mini])', 'me:case-insensitive-reverse-sort', async () => {
  const editor = atom.workspace.getActiveTextEditor()
  const editorView = atom.views.getView(editor)
  await atom.commands.dispatch(editorView, 'sort-lines:case-insensitive-sort')
  await atom.commands.dispatch(editorView, 'sort-lines:reverse')
})