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 * `gh`: select to line begin
* `gl`: select to line end * `gl`: select to line end
* `gi`: select to line begin (non blank)
* `gg`, `gk`: go to the first line * `gg`, `gk`: go to the first line
* `gj`: go to the last line * `gj`: go to the last line

View File

@ -306,6 +306,7 @@ Changes
Goto Commands Goto Commands
------------- -------------
If a count is given prior to hitting *g*, *g* will jump to the given line If a count is given prior to hitting *g*, *g* will jump to the given line
*gh*:: *gh*::
@ -314,6 +315,9 @@ If a count is given prior to hitting *g*, *g* will jump to the given line
*gl*:: *gl*::
select to line end select to line end
*gi*::
select to non blank line start
*gg*, *gk*:: *gg*, *gk*::
go to the first line go to the first line

View File

@ -141,6 +141,9 @@ void goto_commands(Context& context, NormalParams params)
case 'h': case 'h':
select<mode, select_to_line_begin<true>>(context, {}); select<mode, select_to_line_begin<true>>(context, {});
break; break;
case 'i':
select<mode, select_to_first_non_blank>(context, {});
break;
case 'j': case 'j':
context.push_jump(); context.push_jump();
select_coord<mode>(buffer, buffer.line_count() - 1, context.selections()); select_coord<mode>(buffer, buffer.line_count() - 1, context.selections());
@ -233,6 +236,7 @@ void goto_commands(Context& context, NormalParams params)
"g,k: buffer top \n" "g,k: buffer top \n"
"l: line end \n" "l: line end \n"
"h: line begin \n" "h: line begin \n"
"i: line non blank start\n"
"j: buffer bottom \n" "j: buffer bottom \n"
"e: buffer end \n" "e: buffer end \n"
"t: window top \n" "t: window top \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<false>(const Buffer&, const Selection&);
template Selection select_to_line_begin<true>(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) Selection select_matching(const Buffer& buffer, const Selection& selection)
{ {
Vector<Codepoint> matching_pairs = { '(', ')', '{', '}', '[', ']', '<', '>' }; 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> template<bool only_move>
Selection select_to_line_begin(const Buffer& buffer, const Selection& selection); 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 enum class ObjectFlags
{ {
ToBegin = 1, ToBegin = 1,