Skip to content

Instantly share code, notes, and snippets.

@taiar
Created October 6, 2024 16:21
Show Gist options
  • Save taiar/69d64e64a412c563128e81239ca5ff72 to your computer and use it in GitHub Desktop.
Save taiar/69d64e64a412c563128e81239ca5ff72 to your computer and use it in GitHub Desktop.
csv to where sublime plugin
[
{"caption": "CSV to Where", "command": "format_as_where"}
]
import sublime
import sublime_plugin
class FormatAsWhereCommand(sublime_plugin.TextCommand):
def run(self, edit):
# return a list with all lines of the current file
lines = self.view.lines(sublime.Region(0, self.view.size()))
# join lines as strings with comma and space
text = "IN ('" + "', '".join([self.view.substr(line) for line in lines]) + "')"
# replace the content of the current file with the formatted text
self.view.replace(edit, sublime.Region(0, self.view.size()), text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment