diff options
author | Simon Ruderich <simon@ruderich.org> | 2010-09-26 16:28:48 +0000 |
---|---|---|
committer | Simon Ruderich <simon@ruderich.org> | 2010-09-26 16:28:48 +0000 |
commit | 43a7e2a8eda7191f3dd22bba6ebd62a17d29e83d (patch) | |
tree | 48ce53e5666b8f41ae6243215fa898fa98657962 /vim-mode | |
parent | vim_mode: Don't run the operator if the position hasn't changed. (diff) | |
download | irssi-scripts-43a7e2a8eda7191f3dd22bba6ebd62a17d29e83d.tar.gz irssi-scripts-43a7e2a8eda7191f3dd22bba6ebd62a17d29e83d.zip |
vim_mode: Implement . (repeat).
Diffstat (limited to '')
-rw-r--r-- | vim-mode/vim_mode.pl | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 4d1abec..49c8947 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -73,12 +73,18 @@ my @ex_buf; # for commands like 10x my $numeric_prefix = undef; - # vi operators like d, c, .. my $operator = undef; - # vi movements, only used when a movement needs more than one key (like f t). my $movement = undef; +# last vi command, used by . +my $last + = { + 'char' => undef, + 'numeric_prefix' => undef, + 'operator' => undef, + 'movement' => undef + }; # what Vi mode we're in. We start in insert mode. my $mode = M_INS; @@ -155,6 +161,7 @@ my $movements 'P' => { func => \&cmd_movement_P }, # misc '~' => { func => \&cmd_movement_tilde }, + '.' => {}, }; # special movements which take an additional key @@ -651,6 +658,16 @@ sub handle_command { } elsif ($movement || exists $movements->{$char}) { print "Processing movement command: $char" if DEBUG; + # . repeats the last command. + if ($char eq '.' and !$movement and defined $last->{char}) { + $char = $last->{char}; + $numeric_prefix = $last->{numeric_prefix}; + $operator = $last->{operator}; + $movement = $last->{movement}; + print "Repeating: $numeric_prefix$operator$char ($movement)" + if DEBUG; + } + $numeric_prefix = 1 if not $numeric_prefix; # Execute the movement (multiple times). @@ -672,10 +689,16 @@ sub handle_command { if ($operator and $cur_pos != $new_pos) { print "Processing operator: ", $operator if DEBUG; $operators->{$operator}->{func}->($cur_pos, $new_pos, $char); - $operator = undef; } + # Store command, necessary for . + $last->{char} = $char; + $last->{numeric_prefix} = $numeric_prefix; + $last->{operator} = $operator; + $last->{movement} = $movement; + $numeric_prefix = undef; + $operator = undef; $movement = undef; # Start Ex mode. |