Skip to content

Instantly share code, notes, and snippets.

@sjl
Created August 2, 2011 18:36
Show Gist options
  • Save sjl/1120856 to your computer and use it in GitHub Desktop.
Save sjl/1120856 to your computer and use it in GitHub Desktop.
class Vi < Plugin
@mode = 'normal'
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/, /Firefox/ do
map "h" { Vi.mode == 'normal' ? send("<Left>") : send("h") };
map "j" { Vi.mode == 'normal' ? send("<Down>") : send("j") };
map "k" { Vi.mode == 'normal' ? send("<Up>") : send("k") };
map "l" { Vi.mode == 'normal' ? send("<Right>") : send("l") };
map "<Escape>" { Vi.mode == 'normal' ? send("<Escape>") : Vi.toggle }
map "i" { Vi.mode == 'normal' ? Vi.toggle : send("i") };
map "a" do
if Vi.mode == 'normal'
Vi.toggle
send("<Right>")
else
send("a")
end
end
map "A" do
if Vi.mode == 'normal'
Vi.toggle
send("<Ctrl-e>")
else
send("A")
end
end
map "w" { Vi.mode == 'normal' ? send("<Alt-Right><Right>") : send("w") };
map "b" { Vi.mode == 'normal' ? send("<Alt-Left>") : send("b") };
map "e" { Vi.mode == 'normal' ? send("<Alt-Right>") : send("e") };
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment