aboutsummaryrefslogtreecommitdiffstats
path: root/vim-mode/vim_mode.pl
diff options
context:
space:
mode:
authorSimon Ruderich <simon@ruderich.org>2010-09-25 22:35:14 +0000
committerSimon Ruderich <simon@ruderich.org>2010-09-25 22:35:14 +0000
commit1587c8f9fb856582e9390b2f1e1fd50c0b72b7c4 (patch)
tree0b8b731534c5a3a9d8b28d2afdb6056d94c69ee0 /vim-mode/vim_mode.pl
parentvim_mode: Minor documentation update. (diff)
downloadirssi-scripts-1587c8f9fb856582e9390b2f1e1fd50c0b72b7c4.tar.gz
irssi-scripts-1587c8f9fb856582e9390b2f1e1fd50c0b72b7c4.zip
vim_mode: Add support for t,T,f,T.
Diffstat (limited to 'vim-mode/vim_mode.pl')
-rw-r--r--vim-mode/vim_mode.pl62
1 files changed, 62 insertions, 0 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl
index af7366b..e36c41e 100644
--- a/vim-mode/vim_mode.pl
+++ b/vim-mode/vim_mode.pl
@@ -102,6 +102,11 @@ my $operators
= {
'c' => { func => \&cmd_operator_c },
'd' => { func => \&cmd_operator_d },
+ # char movement, works like an operator
+ 'f' => { func => \&cmd_movement_f },
+ 't' => { func => \&cmd_movement_t },
+ 'F' => { func => \&cmd_movement_F },
+ 'T' => { func => \&cmd_movement_T },
};
# vi-moves like w,b; they move the cursor and may get combined with an
@@ -173,6 +178,53 @@ sub cmd_movement_l {
_input_pos($pos);
}
+sub cmd_movement_f {
+ my ($count, $pos, $char) = @_;
+
+ $pos = _next_occurrence(_input(), $char, $count, $pos);
+ if ($pos != -1) {
+ _input_pos($pos);
+ }
+}
+sub cmd_movement_t {
+ my ($count, $pos, $char) = @_;
+
+ $pos = _next_occurrence(_input(), $char, $count, $pos);
+ if ($pos != -1) {
+ _input_pos($pos - 1);
+ }
+}
+sub cmd_movement_F {
+ my ($count, $pos, $char) = @_;
+
+ my $input = reverse _input();
+ $pos = _next_occurrence($input, $char, $count, length($input) - $pos - 1);
+ if ($pos != -1) {
+ _input_pos(length($input) - $pos - 1);
+ }
+}
+sub cmd_movement_T {
+ my ($count, $pos, $char) = @_;
+
+ my $input = reverse _input();
+ $pos = _next_occurrence($input, $char, $count, length($input) - $pos - 1);
+ if ($pos != -1) {
+ _input_pos(length($input) - $pos - 1 + 1);
+ }
+}
+# Find $count-th next occurrence of $char.
+sub _next_occurrence {
+ my ($input, $char, $count, $pos) = @_;
+
+ while ($count-- > 0) {
+ $pos = index $input, $char, $pos + 1;
+ if ($pos == -1) {
+ return -1;
+ }
+ }
+ return $pos;
+}
+
sub cmd_movement_w {
my ($count, $pos) = @_;
@@ -408,6 +460,16 @@ sub handle_command {
print "Processing numeric prefix: $char" if DEBUG;
handle_numeric_prefix($char);
+ # Special case for f,t,F,T as they take an additional argument
+ } elsif ($operator and
+ ($operator eq 'f' or $operator eq 't' or
+ $operator eq 'F' or $operator eq 'T')) {
+ $numeric_prefix = 1 if not $numeric_prefix;
+ $operators->{$operator}->{func}
+ ->($numeric_prefix, _input_pos(), $char);
+ $operator = undef;
+ $numeric_prefix = undef;
+
} elsif (exists $operators->{$char}) {
print "Processing operator: $char" if DEBUG;