Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ahk-viper-mode : toggle emacs keybindings


  • Please log in to reply
No replies to this topic
tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
Laszlo has previously posted a solution for toggling groups of hotkeys.

This is much easier with Lexikos' build of AutoHotkey.

Here is my ahk implementation of a vim or viper mode for emacs.
I think its actually better not to use a hidden window, because then i don't remember which group of keys is active now. So I just keep a window stub in the taskbar (unhidden) instead.

; viper.ahk
;; copyright: Naveen Garg, GPL v2: http://www.gnu.org/licenses/gpl-2.0.html
;; requires: AutoHotkey_L by Lexikos or AutoHotkey.dll by tinku99
!i::     
viperize()
Return


viperize()
{
  Gui 11:Destroy
  Gui 11:Show, Minimize, viperOn ; Hide,
   }

unviperize()
  {
  Gui 11:Destroy
}

#If WinExist("viperOn") and WinActive("ahk_class Emacs")
i::unviperize()
a::send, ^a
m::send, ^{space}  ;; set mark
e::send, ^e
j::
n::
  send, ^n
  return
  
p::
k::
send, ^p
return
,::send, +!,  ;; beginning of page
.::send, +!.  ;; end of page
[::send, !a
]::send, !e  

d::send, ^d  ;; kill letter
^d::send, ^k ;; kill line
!d::send, ^!k  ;; kill next word or sexp
c::send, ^c  ;; next page
w::send, !w  ;; kill region
y::send, ^y
g::send, ^g  ;; cancel command
b::send, !b
r::Reload
q::send, !q  ;; fill paragraph
u::     ;; undo
-::     ;; undo
  send, +^-  
  return


f:: 
send !f
return

!f:: ;; find file
send, ^x^f
unviperize()
return

o::send, ^xo   ;; other buffer
0::send, ^x0  ;; only other buffer
1::send, ^x1  ;; only this buffer
6::send, ^6   ;; don't know what this does
^b::send, ^x^b ;; switch buffers
!b::  ;; switch to buffer by name
  send, ^xb
  unviperize()
  return
9::  
  if !defining
  {
    send, ^x(  
    defining = 1
  }
  else
  {
    send, ^x)
    defining =   
  }
 return
^e:: send, ^xe ;; run keyboard macro  

  
/::
  send, ^s ;; search
  unviperize()
  return
^/::
  send, ^r ;; search
  unviperize()
  return
    
s::send, ^x^s  ;; save file
x::  ;; minibuffer command
  send, !x
  unviperize()
  return


!r::Reload

#If