aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h3
-rw-r--r--vis.c6
-rw-r--r--window.c21
-rw-r--r--window.h3
4 files changed, 31 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h
index bab72f5..3061aef 100644
--- a/config.def.h
+++ b/config.def.h
@@ -130,6 +130,9 @@ static KeyBinding vis_movements[] = {
{ { NONE('(') }, movement, { .i = MOVE_SENTENCE_PREV } },
{ { NONE(')') }, movement, { .i = MOVE_SENTENCE_NEXT } },
{ { NONE('g'), NONE('g') }, movement, { .i = MOVE_FILE_BEGIN } },
+ { { NONE('g'), NONE('0') }, movement, { .i = MOVE_SCREEN_LINE_BEGIN } },
+ { { NONE('g'), NONE('m') }, movement, { .i = MOVE_SCREEN_LINE_MIDDLE} },
+ { { NONE('g'), NONE('$') }, movement, { .i = MOVE_SCREEN_LINE_END } },
{ { NONE('G') }, movement, { .i = MOVE_LINE } },
{ { NONE('|') }, movement, { .i = MOVE_COLUMN } },
{ { NONE('n') }, movement, { .i = MOVE_SEARCH_FORWARD } },
diff --git a/vis.c b/vis.c
index 3add37a..24982e9 100644
--- a/vis.c
+++ b/vis.c
@@ -189,6 +189,9 @@ static Operator ops[] = {
enum {
MOVE_SCREEN_LINE_UP,
MOVE_SCREEN_LINE_DOWN,
+ MOVE_SCREEN_LINE_BEGIN,
+ MOVE_SCREEN_LINE_MIDDLE,
+ MOVE_SCREEN_LINE_END,
MOVE_LINE_PREV,
MOVE_LINE_BEGIN,
MOVE_LINE_START,
@@ -253,6 +256,9 @@ static size_t window_lines_bottom(const Arg *arg);
static Movement moves[] = {
[MOVE_SCREEN_LINE_UP] = { .win = window_line_up },
[MOVE_SCREEN_LINE_DOWN]= { .win = window_line_down },
+ [MOVE_SCREEN_LINE_BEGIN] = { .win = window_line_begin, .type = CHARWISE },
+ [MOVE_SCREEN_LINE_MIDDLE] = { .win = window_line_middle,.type = CHARWISE },
+ [MOVE_SCREEN_LINE_END] = { .win = window_line_end, .type = CHARWISE|INCLUSIVE },
[MOVE_LINE_PREV] = { .txt = text_line_prev, .type = LINEWISE },
[MOVE_LINE_BEGIN] = { .txt = text_line_begin, .type = LINEWISE },
[MOVE_LINE_START] = { .txt = text_line_start, .type = LINEWISE },
diff --git a/window.c b/window.c
index 716d9e5..cb22f56 100644
--- a/window.c
+++ b/window.c
@@ -79,7 +79,7 @@ static void window_clear(Win *win);
static bool window_addch(Win *win, Char *c);
static size_t window_cursor_update(Win *win);
/* set/move current cursor position to a given (line, column) pair */
-static void window_cursor_set(Win *win, Line *line, int col);
+static size_t window_cursor_set(Win *win, Line *line, int col);
/* move visible viewport n-lines up/down, redraws the window but does not change
* cursor position which becomes invalid and should be corrected by either:
*
@@ -563,7 +563,7 @@ size_t window_char_next(Win *win) {
return window_cursor_update(win);
}
-static void window_cursor_set(Win *win, Line *line, int col) {
+static size_t window_cursor_set(Win *win, Line *line, int col) {
int row = 0;
size_t pos = win->start;
Cursor *cursor = &win->cursor;
@@ -589,6 +589,8 @@ static void window_cursor_set(Win *win, Line *line, int col) {
cursor->line = line;
window_cursor_update(win);
+
+ return pos;
}
static bool window_viewport_down(Win *win, int n) {
@@ -705,6 +707,21 @@ size_t window_line_down(Win *win) {
return cursor->pos;
}
+size_t window_line_begin(Win *win) {
+ return window_cursor_set(win, win->cursor.line, 0);
+}
+
+size_t window_line_middle(Win *win) {
+ Cursor *cursor = &win->cursor;
+ return window_cursor_set(win, cursor->line, cursor->line->width / 2);
+}
+
+size_t window_line_end(Win *win) {
+ Cursor *cursor = &win->cursor;
+ int col = cursor->line->width - 1;
+ return window_cursor_set(win, cursor->line, col >= 0 ? col : 0);
+}
+
void window_update(Win *win) {
wnoutrefresh(win->win);
}
diff --git a/window.h b/window.h
index 816efcd..6c4b72f 100644
--- a/window.h
+++ b/window.h
@@ -33,6 +33,9 @@ size_t window_char_next(Win*);
size_t window_char_prev(Win*);
size_t window_line_down(Win*);
size_t window_line_up(Win*);
+size_t window_line_begin(Win*);
+size_t window_line_middle(Win*);
+size_t window_line_end(Win*);
/* move window content up/down, but keep cursor position unchanged unless it is
* on a now invisible line in which case we try to preserve the column position */
size_t window_slide_up(Win*, int lines);