Add gi to go to first non-blank character on line

Fixes #407
This commit is contained in:
Maxime Coste 2017-01-22 23:53:08 +00:00
parent 66e422e397
commit 7ba24c043a
5 changed files with 30 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -141,6 +141,9 @@ void goto_commands(Context& context, NormalParams params)
case 'h':
select<mode, select_to_line_begin<true>>(context, {});
break;
case 'i':
select<mode, select_to_first_non_blank>(context, {});
break;
case 'j':
context.push_jump();
select_coord<mode>(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");
}
}

View File

@ -181,6 +181,14 @@ Selection select_to_line_begin(const Buffer& buffer, const Selection& selection)
template Selection select_to_line_begin<false>(const Buffer&, const Selection&);
template Selection select_to_line_begin<true>(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<Codepoint> matching_pairs = { '(', ')', '{', '}', '[', ']', '<', '>' };

View File

@ -40,6 +40,8 @@ Selection select_to_line_end(const Buffer& buffer, const Selection& selection);
template<bool only_move>
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,