topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 7:07 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Free Windows Text Editor that transposes last 2 characters typed on Control-t ??  (Read 7043 times)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Subject line says it.  I'm looking for a Free Windows Text Editor that transposes last 2 characters typed on Control-t ??  XEmacs is the only one I seem to remember that does it on Windows.  But I don't want to suffer through the rest of the learning curve.

Failing that maybe one where you can add a hotkey and custom command easily?
That's the most common typo for me and I can't believe it's not a standard feature like deleting a line.

edit: I know the editor in Visual Studio 2008 does it, but I don't want to wait 3 minutes for it to open.  Looking for something like EditPad Lite or NotePad++ but with Control-t transpose function.
« Last Edit: July 23, 2010, 01:19 PM by MilesAhead »

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
Or you could write a short Autohotkey script that would fix your typo with a Control-t no matter where you were typing (eg the Quick Reply in a DonationCoder forum  ;)  )

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Yeah, but then I'd have to decide if I should pass it through or eat the key.  Control T is a pretty common hotkey that's likely to do something else in an editor. I don't know why more editors don't have transpose.  Doesn't anyone touch type?

edit: plus I think the method would end up being pretty sloppy.  Send keys, copy to clipboard, etc.. which is likely to interfere with the clipboard likely to be in use by the editor. It would be smoother all around if the function was built in.

« Last Edit: July 23, 2010, 04:19 PM by MilesAhead »

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
If transposing the last two letters of a word only happens in your text editor, then by all means write a Control-T macro for that editor.  I use Boxer and Word and it would be easy to write a macro for either.

But if it happens elsewhere, I'd still think about a system-wide macro.  If Control-t is too general, pick something more obscure (Shift-Ctrl-1, Ctrl-Alt-q).

If the cursor is already at the end of the word, seems like the code would be a simple SelectOneCharacterToLeft,Cut,CursorLeft,Paste - only four keys to send:  ShiftCursorLeft/Ctrl-x/CursorLeft/Ctrl-v .  This should work regardless of which clipboard is used (system or editor) if the editor uses Ctrl-x and Ctrl-v to cut and paste using it's internal clipboard (Boxer does this).
 
I take your point about bumping whatever was originally in the clipboard.  I use a clipboard manager with quick hotkeys to jump to an earlier clip.

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
Or if  you already have a text editor you like, write an autohotkey script that is only active when that editor has focus.  You'd still overwrite the current clipboard contents but you wouldn't have to worry about a Ctrl-t conflict.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
There is no need to use the clipboard.  Consider the following AHK code:

Code: Autohotkey [Select]
  1. {
  2.     Key_3 := Key_2, Key_2 := Key_1
  3.     Input, Key_1, V I L1
  4. }
  5. Return
  6.  
  7.  
  8. ^t::
  9. {
  10.     SendInput, {Backspace 2}
  11.     SendInput, % Key_2 . Key_3
  12. }
  13. Return

The above snippet should work anywhere to swap the last two typed characters without using the clipboard.  Alternately, you could easily restrict it down to only certain applications.  Obviously, minimal testing has been done with this but it seems to work pretty well.
« Last Edit: July 24, 2010, 01:43 AM by skwire »

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
There is no need to use the clipboard.

That's much better!

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Thanks for the macro and ahk code. :)

edit: thanks skwire.  Tried it in EditPadLite and it worked.  :)
« Last Edit: July 25, 2010, 05:40 PM by MilesAhead »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
I just added a few lines to restrict the windows to a group of editors using the class names.

edit: added Chrome and Firefox browsers to the window group

GroupAdd,EditorGroup, ahk_class TFormEditPadLite  ;EditPadLite
GroupAdd,EditorGroup, ahk_class wxWindowClassNR   ;FBIde
GroupAdd,EditorGroup, ahk_class SciTEWindow       ;Scite
GroupAdd,EditorGroup, ahk_class MAINFBEDIT        ;FBEdit
GroupAdd,EditorGroup, ahk_class Notepad           ;Notepad
GroupAdd,EditorGroup, ahk_class TFormMain         ;TreePad
GroupAdd,EditorGroup, ahk_class Chrome_WidgetWin_0   ;Chrome Browser
GroupAdd,EditorGroup, ahk_class MozillaUIWindowClass ;Firefox Browser

Loop
{
    Key_3 := Key_2, Key_2 := Key_1
    Input, Key_1, V I L1
}
Return

#IfWinActive, ahk_group EditorGroup
^t::
{
    SendInput, {Backspace 2}
    SendInput, % Key_2 . Key_3
}
Return
« Last Edit: July 26, 2010, 09:27 PM by MilesAhead »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Thanks for the macro and ahk code. :)

edit: thanks skwire.  Tried it in EditPadLite and it worked.  :)

You're welcome.  Happy to help.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Looking around on ahk forum I saw that I was overly concerned about the clipboard when doing a hotkey for transposing characters. Using the clipboard has the advantage that I can move the caret, then later come back and fix a transpose typo.  This implementation is just a minimal macro.  It will not work correctly unless there are at least 2 characters to the left of the caret when you hit the hotkey. If the caret is at the start of a line or to the right of the first character, the macro will just end up eating a character. Also the app taking the input must be in Insert Mode.  Still, I get quite a bit of use out of it.  Anytime I want to add an app I just check that the app doesn't use ^t itself, then add its class name to the list for the window group.

#SingleInstance force
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
GroupAdd,EditorGroup, ahk_class TFormEditPadLite  ;EditPadLite
GroupAdd,EditorGroup, ahk_class wxWindowClassNR   ;FBIde
GroupAdd,EditorGroup, ahk_class SciTEWindow       ;Scite
GroupAdd,EditorGroup, ahk_class MAINFBEDIT        ;FBEdit
GroupAdd,EditorGroup, ahk_class Notepad           ;Notepad
GroupAdd,EditorGroup, ahk_class TFormMain         ;TreePad
GroupAdd,EditorGroup, ahk_class Chrome_WidgetWin_0   ;Chrome Browser
GroupAdd,EditorGroup, ahk_class MozillaUIWindowClass ;Firefox Browser

#IfWinActive, ahk_Group EditorGroup
^t::
  ClipSaved := ClipboardAll ; save entire clipboard
  Clipboard= ; clear clipboard
  Send {Shift Down}{Left}{Shift Up} ; select char left of caret
  Send ^c ; copy char
  ClipWait,0 ;give copy time to complete
  ; the caret is positioned to insert
  ; the char from the clipboard. Editor
  ; must be in Insert Mode for it to work.
  ; The char is inserted, and caret positon restored.
  ;
  Send {Right}
  Send {BackSpace}
  Send {Left}
  Send {Raw}%Clipboard% ; avoid puntuaction being interpreted
  Send {Right}
  Clipboard := ClipSaved
  ClipSaved = ; free memory
Return