From 7ba24c043aced097631e21463d79b21b17442a4e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 22 Jan 2017 23:53:08 +0000 Subject: [PATCH] Add `gi` to go to first non-blank character on line Fixes #407 --- README.asciidoc | 1 + doc/manpages/shortcuts.asciidoc | 4 ++++ src/normal.cc | 26 +++++++++++++++----------- src/selectors.cc | 8 ++++++++ src/selectors.hh | 2 ++ 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index c5a824a0..72c97b2c 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -472,6 +472,7 @@ Commands beginning with g are used to goto certain position and or buffer: * `gh`: select to line begin * `gl`: select to line end + * `gi`: select to line begin (non blank) * `gg`, `gk`: go to the first line * `gj`: go to the last line diff --git a/doc/manpages/shortcuts.asciidoc b/doc/manpages/shortcuts.asciidoc index 46dcc171..b2595241 100644 --- a/doc/manpages/shortcuts.asciidoc +++ b/doc/manpages/shortcuts.asciidoc @@ -306,6 +306,7 @@ Changes Goto Commands ------------- + If a count is given prior to hitting *g*, *g* will jump to the given line *gh*:: @@ -314,6 +315,9 @@ If a count is given prior to hitting *g*, *g* will jump to the given line *gl*:: select to line end +*gi*:: + select to non blank line start + *gg*, *gk*:: go to the first line diff --git a/src/normal.cc b/src/normal.cc index af72e000..1f0f6e5a 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -141,6 +141,9 @@ void goto_commands(Context& context, NormalParams params) case 'h': select>(context, {}); break; + case 'i': + select(context, {}); + break; case 'j': context.push_jump(); select_coord(buffer, buffer.line_count() - 1, context.selections()); @@ -230,17 +233,18 @@ void goto_commands(Context& context, NormalParams params) } } }, "goto", - "g,k: buffer top \n" - "l: line end \n" - "h: line begin \n" - "j: buffer bottom \n" - "e: buffer end \n" - "t: window top \n" - "b: window bottom \n" - "c: window center \n" - "a: last buffer \n" - "f: file \n" - ".: last buffer change\n"); + "g,k: buffer top \n" + "l: line end \n" + "h: line begin \n" + "i: line non blank start\n" + "j: buffer bottom \n" + "e: buffer end \n" + "t: window top \n" + "b: window bottom \n" + "c: window center \n" + "a: last buffer \n" + "f: file \n" + ".: last buffer change \n"); } } diff --git a/src/selectors.cc b/src/selectors.cc index 598aff70..43c376e1 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -181,6 +181,14 @@ Selection select_to_line_begin(const Buffer& buffer, const Selection& selection) template Selection select_to_line_begin(const Buffer&, const Selection&); template Selection select_to_line_begin(const Buffer&, const Selection&); +Selection select_to_first_non_blank(const Buffer& buffer, const Selection& selection) +{ + auto it = buffer.iterator_at(selection.cursor().line); + skip_while(it, buffer.iterator_at(selection.cursor().line+1), + is_horizontal_blank); + return {it.coord()}; +} + Selection select_matching(const Buffer& buffer, const Selection& selection) { Vector matching_pairs = { '(', ')', '{', '}', '[', ']', '<', '>' }; diff --git a/src/selectors.hh b/src/selectors.hh index 6933a6b2..737550d2 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -40,6 +40,8 @@ Selection select_to_line_end(const Buffer& buffer, const Selection& selection); template Selection select_to_line_begin(const Buffer& buffer, const Selection& selection); +Selection select_to_first_non_blank(const Buffer& buffer, const Selection& selection); + enum class ObjectFlags { ToBegin = 1,