The main reason I wrote this was to keep the window position when sorting. The built-in command scrolls elsewhere.
It also deletes any duplicate lines.
Here’s the code.
import sublime, sublime_plugin
# Written by Stephen.S on 2021.04.23.
# To get over the bug in ST where the window position is not remembered.
# Also removes any duplicate lines.
class SortlinesRemoveDuplicatesKeepWinPosition(sublime_plugin.TextCommand):
def run(self, view):
view = self.view
col, row = view.viewport_position() # Get the position of the window.
view.run_command('sort_lines', {"case_sensitive": False, "reverse": False, "remove_duplicates": True})
view.set_viewport_position([col, row]) # Set the position of the window.