diff options
Diffstat (limited to 'vim-mode/vim_mode.pl')
-rw-r--r-- | vim-mode/vim_mode.pl | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 4e7bc72..75a8af9 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -81,6 +81,8 @@ my $movement = undef; # what Vi mode we're in. We start in insert mode. my $mode = M_INS; +# index into the history list (for j,k) +my $history_index = undef; sub script_is_loaded { my $name = shift; @@ -115,8 +117,8 @@ my $movements # arrow like movement 'h' => { func => \&cmd_movement_h }, 'l' => { func => \&cmd_movement_l }, - #'j' => { func => \&cmd_movement_j }, - #'k' => { func => \&cmd_movement_k }, + 'j' => { func => \&cmd_movement_j }, + 'k' => { func => \&cmd_movement_k }, # char movement, take an additional parameter and use $movement 'f' => { func => \&cmd_movement_f }, 't' => { func => \&cmd_movement_t }, @@ -179,6 +181,46 @@ sub cmd_operator_d { _input_pos($old_pos); } +# later history (down) +sub cmd_movement_j { + my ($count, $pos) = @_; + + my @history = Irssi::active_win->get_history_lines(); + + if (defined $history_index) { + $history_index += $count; + print "History Index: $history_index" if DEBUG; + } else { + $history_index = $#history; + } + + if ($history_index > $#history) { + _input(''); + _input_pos(0); + $history_index = $#history + 1; + } else { + _input($history[$history_index]); + _input_pos(0); + } +} + +# earlier history (up) +sub cmd_movement_k { + my ($count, $pos) = @_; + + my @history = Irssi::active_win->get_history_lines(); + + if (defined $history_index) { + $history_index -= $count; + $history_index = 0 if $history_index < 0; + } else { + $history_index = $#history; + } + print "History Index: $history_index" if DEBUG; + _input($history[$history_index]); + _input_pos(0); +} + sub cmd_movement_h { my ($count, $pos) = @_; @@ -534,6 +576,7 @@ sub handle_command { _set_prompt(':'); # Enter key sends the current input line in command mode as well. + } elsif ($key == 10) { my $input = _input(); my $cmdchars = Irssi::settings_get_str('cmdchars'); @@ -544,6 +587,9 @@ sub handle_command { } else { $signal = 'send text'; } + # TODO: don't try to send this signal unless server and win are + # defined (At least for 'send text' signals. There's no reason + # to send text to an empty window anyway(?) Irssi::signal_emit $signal, $input, Irssi::active_server(), Irssi::active_win()->{active}; _input(''); @@ -602,6 +648,9 @@ sub _stop() { sub _update_mode { my ($new_mode) = @_; $mode = $new_mode; + if ($mode == M_INS) { + $history_index = undef; + } Irssi::statusbar_items_redraw("vim_mode"); } |