This is @deathaxe 's plugin. It’s a bit old I’ve subsequently realised which is why I had to kill ST3, or it might have died before I hit the enter button (I had to find PID etc)
Any chance of some tweaks so it doesn’t blow up my machine please. (There’s an also at the end if you don’t mind…)
import sublime
import sublime_plugin
class FindReplaceCommand(sublime_plugin.TextCommand):
"""The implementation of 'find_replace' text command.
Example:
view.run_command(
"find_replace", {
"pattern": "the",
"replace_by": "THE",
"start_pt": 100,
"flags": ["LITERAL"]
}
)
"""
FLAGS = {
"LITERAL": sublime.LITERAL,
"IGNORECASE": sublime.IGNORECASE
}
def run(self, edit, pattern, replace_by, start_pt=0, flags=[]):
"""Find and replace all patterns.
Arguments:
edit (sublime.Edit):
The edit token used to undo this command.
pattern (string):
The regex pattern to use for finding.
replace_by (string):
The text to replace all found words by.
start_pt (int):
The text position where to start.
flags (list):
The flags to pass to view.find()
["LITERAL", "IGNORECASE"]
"""
while True:
found = self.view.find(pattern, self._flags(flags), start_pt)
if not found:
return
self.view.replace(edit, found, replace_by)
start_pt = found.begin()
def _flags(self, flags):
"""Translate list of flags."""
result = 0
for flag in flags:
result |= self.FLAGS.get(flag, 0)
return result
How could I mod this code so that pattern, initial value could be assigned by the selected text, replace_by by ctrl+shift+e, start_pt by position of caret/cursor, like how ctrl+h works. Does this make sense ? So I can get input from the keyboard etc.
I include the keybinding I used too:
{ "keys": ["alt+f","alt+r"],
"command": "find_replace",
"args":{
"pattern": "the",
"replace_by":"THE",
"start_pt":0,
"flags":["LITERAL"]}}
Cheers !!