Skip to content

Instantly share code, notes, and snippets.

View OdatNurd's full-sized avatar

Terence Martin OdatNurd

View GitHub Profile
@OdatNurd
OdatNurd / edit_examples.py
Created December 21, 2020 07:28
Sample plugin showing how to edit, replace and erase text in a Sublime Text plugoin
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World!")
class SecondExampleCommand(sublime_plugin.TextCommand):
@OdatNurd
OdatNurd / do_find.py
Created December 28, 2020 17:31
Plugin 101 Lesson 20 examples
import sublime
import sublime_plugin
class DoFindReplaceCommand(sublime_plugin.TextCommand):
"""
Find all instances of the search text and replace it with the replacement
text provided. The arguments allow you to decide if the command should be a
regular expression (the default) or just plain text, and whether or not
case should be ignored or not (by default it is not).
@OdatNurd
OdatNurd / selection_test.py
Created January 18, 2021 04:36
Plugin 101 Lesson 21 examples
import sublime
import sublime_plugin
class ReverseSelectAllCommand(sublime_plugin.TextCommand):
def run(self, edit):
span = sublime.Region(len(self.view), 0)
self.view.sel().add(span)
@OdatNurd
OdatNurd / Default.sublime-commands
Created January 20, 2021 05:16
Easily open the Sublime Plugin API files
[
{ "caption": "Developer: Open API Files", "command": "open_api_files" },
]
@OdatNurd
OdatNurd / snippet_folder.py
Created February 15, 2021 09:30
Sublime Text 4 plugin to expand snippets and automatically fold parts of them up
import sublime
import sublime_plugin
class ExpandAndFoldSnippetCommand(sublime_plugin.TextCommand):
def run(self, edit, name, folds):
self.view.run_command("insert_snippet", {"name": name})
for _ in range(folds):
self.view.run_command("fold")
@OdatNurd
OdatNurd / Default (PLATFORM).sublime-keymap
Created March 4, 2021 23:16
Closing a Terminus view and pane at the same time
[
// If you use the Chain of Command package, use this binding to chain
// the two required commands together.
{ "keys": ["ctrl+shift+h"], "command": "chain",
"args": {
"commands": [
["terminus_close"],
["destroy_pane", {"direction": "self"}]
]
},
@OdatNurd
OdatNurd / hover_bookmark_toggle.py
Created March 10, 2021 23:34
Sublime Text 3 bookmark hover toggle
import sublime
import sublime_plugin
class BookmarkEventListener(sublime_plugin.EventListener):
def toggle_bookmarks(self, view, point):
# Get existing bookmarks and create a region for the new one
bookmarks = view.get_regions("bookmarks")
new = sublime.Region(point)
@OdatNurd
OdatNurd / region_sample.py
Created May 19, 2021 05:55
Sample of using regions in Sublime Text plugins
import sublime
import sublime_plugin
_types = {
"IDII": 7,
"SEDOL": 7,
"DATE": 7,
"TYPE": 1
}
@OdatNurd
OdatNurd / Sample.sublime-build
Created May 26, 2021 04:51
Sample Sublime plugin for adding custom variables
{
"target": "my_custom_build",
"cancel": {"kill": true},
"shell_cmd": "echo \\${docs}"
}
@OdatNurd
OdatNurd / close_other_files.py
Created June 16, 2021 04:50
A simple Sublime Text plugin that allows you to close all files except the one currently being edited.
import sublime
import sublime_plugin
# Sample key binding:
#
# { "keys": ["ctrl+alt+shift+w"], "command": "close_others_shim" },
#
class CloseOtherTabsCommand(sublime_plugin.WindowCommand):
"""