Find and replace last mistake with Autohotkey
Posted: 08 Jul 2012, 01:16
This is a tiny script in Autohotkey_L to correct typing mistakes. Consider this search query (| being the cursor position):
Ctrl+Z to undo.
Doesn't work with special characters*.
To use a different character to invoke the script simply replace \ in the first line (to use Shift+Backspace put "+Backspace::" instead of "\::", f.i.). To edit seperation characters (currently Space, Escape, or Enter) just delete/edit the current ones or add more in the same pattern.
Update 11.07.2012, now restores clipboard when done
since this script works by copying the text to memory, editing it there and pasting it back, it messed up your clipboard contents every time you used it. now it tries to restore them upon completion. it seems there is no way to wait for the paste to complete, so it just waits for 80ms and then restores the clipboard contents ("sleep 80"). if it restores them before paste is executed, your original clipboard contents will get pasted. if this happens (it shouldn't) try increasing the sleep duration to 100 or 150.
Update 11.07.2012 (_ means space)
// . (dot) as wildcard (same as \S+)
"best rest" \r.t_test_ => "best test"
// automatch by characters, if replace string empty
"teh grammer" \the__ => "the grammer"
HowTo install (Windows only)
Should work in all text fields.
* search and replace are regular expressions. If you don't know what these are, only use letters and numbers.
The script enables you to type commands like "\adr andr " (as in "\find replace ") to get this result:best adroid pdf reader|
It searches for the last occurence of "adr" (in the region selectable by Shift+Home) and replaces it with "andr".best android pdf reader|
Ctrl+Z to undo.
Doesn't work with special characters*.
To use a different character to invoke the script simply replace \ in the first line (to use Shift+Backspace put "+Backspace::" instead of "\::", f.i.). To edit seperation characters (currently Space, Escape, or Enter) just delete/edit the current ones or add more in the same pattern.
Update 11.07.2012, now restores clipboard when done
since this script works by copying the text to memory, editing it there and pasting it back, it messed up your clipboard contents every time you used it. now it tries to restore them upon completion. it seems there is no way to wait for the paste to complete, so it just waits for 80ms and then restores the clipboard contents ("sleep 80"). if it restores them before paste is executed, your original clipboard contents will get pasted. if this happens (it shouldn't) try increasing the sleep duration to 100 or 150.
Update 11.07.2012 (_ means space)
// . (dot) as wildcard (same as \S+)
"best rest" \r.t_test_ => "best test"
// automatch by characters, if replace string empty
"teh grammer" \the__ => "the grammer"
Code: Select all
#EscapeChar \
\::
ToolTip replace last occurence of
clipboard_backup := ClipboardAll
search := ""
replace := ""
Input search, , {Space}{Escape}{Enter}
if (ErrorLevel == "EndKey:Escape"
|| search == "")
{
ToolTip
return
}
ToolTip with
Input replace, , {Space}{Escape}{Enter}
if (ErrorLevel == "EndKey:Escape")
{
ToolTip
return
}
if (replace == "")
{
replace := search
l := StrLen(search)
search = [%search%]{%l%}
}
clipboard = ;
SendInput +{Home}^x
ClipWait
search_with_wildcard := RegExReplace(search, "\\.", "\\S+")
search = i)%search_with_wildcard%(?!.*%search_with_wildcard%.*)(.*)$
replace = %replace%$1
;ToolTip %replace% %search%
clipboard := RegExReplace(clipboard, search, replace)
ClipWait
SendInput ^{VK56}
ToolTip
Sleep 80 ; wait for paste
clipboard := clipboard_backup
return
Spoiler:
* search and replace are regular expressions. If you don't know what these are, only use letters and numbers.