Skip to content

Instantly share code, notes, and snippets.

@jbjornson
Created August 29, 2011 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbjornson/1178622 to your computer and use it in GitHub Desktop.
Save jbjornson/1178622 to your computer and use it in GitHub Desktop.
Search for the text in the clipboard and cut the containing line to the clipboard
import sublime, sublime_plugin, re
# Search for the text in the clipboard and cut the containing line to the clipboard
# { "keys": ["alt+x"], "command": "slurp_line_using_clipboard" }
# https://gist.github.com/1178622
class SlurpLineUsingClipboardCommand(sublime_plugin.TextCommand):
def run(self, edit, block=True):
search_string = re.escape(sublime.get_clipboard())
region = self.view.find(search_string, 0, sublime.IGNORECASE)
if region:
# get the full line, copy it to the clipboard and then delete the line
region = self.view.full_line(region)
sublime.set_clipboard( self.view.substr(region))
self.view.erase(edit, region)
else:
print 'Search string "%s" was not found' % (search_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment