From 8dad4e51e4e5cc190d84a266f0a48054f4df8cc4 Mon Sep 17 00:00:00 2001 From: Jonatan Vela Date: Tue, 17 Jan 2017 02:06:29 +0100 Subject: [PATCH] Support vim movements: H M L Vim movements H, M and L implemented and documented. --- README.rst | 6 ++++++ man/termite.1 | 6 ++++++ termite.cc | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/README.rst b/README.rst index 62e41ab..730afd8 100644 --- a/README.rst +++ b/README.rst @@ -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) | diff --git a/man/termite.1 b/man/termite.1 index a007889..93fb29d 100644 --- a/man/termite.1 +++ b/man/termite.1 @@ -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" diff --git a/termite.cc b/termite.cc index 1b10691..6055963 100644 --- a/termite.cc +++ b/termite.cc @@ -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;