AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ahk-viper-mode : toggle emacs keybindings

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
tinku99



Joined: 03 Aug 2007
Posts: 399
Location: Houston, TX

PostPosted: Fri May 15, 2009 4:56 pm    Post subject: ahk-viper-mode : toggle emacs keybindings Reply with quote

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.

Code:

; 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

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group