Merge pull request #441 from wbangna/vim-movement-top-middle-bottom

Vim movement top middle bottom
This commit is contained in:
jelle van der Waa 2017-08-18 21:38:08 +02:00 committed by GitHub
commit 01f8542ffb
3 changed files with 38 additions and 0 deletions

View File

@ -118,6 +118,12 @@ SELECTION MODE
+-----------------------------------+-----------------------------------------------------------+
| ``B`` or ``ctrl-left`` | backward WORD (non-whitespace) |
+-----------------------------------+-----------------------------------------------------------+
| ``H`` | jump to the top of the screen |
+-----------------------------------+-----------------------------------------------------------+
| ``M`` | jump to the middle of the screen |
+-----------------------------------+-----------------------------------------------------------+
| ``L`` | jump to the bottom of the screen |
+-----------------------------------+-----------------------------------------------------------+
| ``0`` or ``home`` | move cursor to the first column in the row |
+-----------------------------------+-----------------------------------------------------------+
| ``^`` | beginning-of-line (first non-blank character) |

View File

@ -109,6 +109,12 @@ forward \fIWORD\fP (non-whitespace)
forward to end of \fIWORD\fP (non-whitespace)
.IP "\fBB\fP or \fBctrl-left\fP"
backward \fIWORD\fP (non-whitespace)
.IP "\fBH\fP"
move cursor to the top of the screen
.IP "\fBM\fP"
move cursor to the middle of the screen
.IP "\fBL\fP"
move cursor to the bottom of the screen
.IP "\fB0\fP or \fBhome\fP"
move cursor to the first column in the row\fP"
.IP "\fB^\fP"

View File

@ -507,6 +507,23 @@ static long last_row(VteTerminal *vte) {
return (long)gtk_adjustment_get_upper(adjust) - 1;
}
static long top_row(VteTerminal *vte) {
GtkAdjustment *adjust = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte));
return (long)gtk_adjustment_get_value(adjust);
}
static long middle_row(VteTerminal *vte) {
GtkAdjustment *adjust = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte));
return (long)gtk_adjustment_get_value(adjust) +
(long)vte_terminal_get_row_count(vte) / 2;
}
static long bottom_row(VteTerminal *vte) {
GtkAdjustment *adjust = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte));
return (long)gtk_adjustment_get_value(adjust) +
(long)vte_terminal_get_row_count(vte) - 1;
}
static void update_scroll(VteTerminal *vte) {
GtkAdjustment *adjust = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte));
const double scroll_row = gtk_adjustment_get_value(adjust);
@ -894,6 +911,15 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info)
case GDK_KEY_G:
move_to_row_start(vte, &info->select, last_row(vte));
break;
case GDK_KEY_H:
move_to_row_start(vte, &info->select, top_row(vte));
break;
case GDK_KEY_M:
move_to_row_start(vte, &info->select, middle_row(vte));
break;
case GDK_KEY_L:
move_to_row_start(vte, &info->select, bottom_row(vte));
break;
case GDK_KEY_v:
toggle_visual(vte, &info->select, vi_mode::visual);
break;