Created
April 23, 2011 05:03
-
-
Save kevincolyar/938316 to your computer and use it in GitHub Desktop.
Sample Keymando Plugin - Vi Input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vi < Plugin | |
@mode = 'insert' | |
class << self; attr_accessor :mode; end | |
def self.normal? | |
lambda { return Vi.mode == 'normal'} | |
end | |
def self.insert? | |
lambda { return Vi.mode == 'insert'} | |
end | |
def self.toggle | |
Vi.mode == 'normal' ? Vi.mode = 'insert' : Vi.mode = 'normal' | |
end | |
def before | |
end | |
def after | |
except /iTerm/, /MacVim/ do | |
# Entering insert mode | |
imap("i", :if => Vi.normal?) { Vi.toggle } | |
imap("a", :if => Vi.normal?) { send("<Ctrl-e>"); Vi.toggle } | |
imap("I", :if => Vi.normal?) { send("<Ctrl-a>"); Vi.toggle } | |
# Entering normal mode | |
imap("<Escape>", :if => Vi.insert?) { Vi.toggle } | |
imap("<Ctrl-[>", :if => Vi.insert?) { Vi.toggle } | |
# Normal mode movement | |
imap "l", "<Right>", :if => Vi.normal? | |
imap "k", "<Up>", :if => Vi.normal? | |
imap "j", "<Down>", :if => Vi.normal? | |
imap "h", "<Left>", :if => Vi.normal? | |
imap "u", "<Cmd-z>", :if => Vi.normal? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment