aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md13
-rw-r--r--config.def.h2
-rw-r--r--text-objects.c17
-rw-r--r--text-objects.h3
-rw-r--r--vis.c4
5 files changed, 35 insertions, 4 deletions
diff --git a/README.md b/README.md
index fef2ff4..a4c99c5 100644
--- a/README.md
+++ b/README.md
@@ -321,10 +321,15 @@ Operators can be forced to work line wise by specifying `V`.
For sentence and paragraph there is no difference between the
inner and normal variants.
- Furthermore `ae` covers the entire content of a file, whereas `ie`
- does not include leading and trailing empty lines. `af` tries to
- match C-like function definitions, `if` only covers the function
- body.
+ Additionally the following text objects, which are not part of stock vim
+ are also supported:
+
+ ae entire file content
+ ie entire file content except for leading and trailing empty lines
+ af C-like function definition including immeadiately preceding comments
+ if C-like function definition only function body
+ al current line
+ il current line without leading and trailing white spaces
### Modes
diff --git a/config.def.h b/config.def.h
index 5269ea4..b8c7e7d 100644
--- a/config.def.h
+++ b/config.def.h
@@ -171,6 +171,7 @@ static KeyBinding vis_textobjs[] = {
{ { NONE('a'), NONE('`') }, textobj, { .i = TEXT_OBJ_OUTER_BACKTICK } },
{ { NONE('a'), NONE('e') }, textobj, { .i = TEXT_OBJ_OUTER_ENTIRE } },
{ { NONE('a'), NONE('f') }, textobj, { .i = TEXT_OBJ_OUTER_FUNCTION } },
+ { { NONE('a'), NONE('l') }, textobj, { .i = TEXT_OBJ_OUTER_LINE } },
{ /* empty last element, array terminator */ },
};
@@ -194,6 +195,7 @@ static KeyBinding vis_inner_textobjs[] = {
{ { NONE('i'), NONE('`') }, textobj, { .i = TEXT_OBJ_INNER_BACKTICK } },
{ { NONE('i'), NONE('e') }, textobj, { .i = TEXT_OBJ_INNER_ENTIRE } },
{ { NONE('i'), NONE('f') }, textobj, { .i = TEXT_OBJ_INNER_FUNCTION } },
+ { { NONE('i'), NONE('l') }, textobj, { .i = TEXT_OBJ_INNER_LINE } },
{ /* empty last element, array terminator */ },
};
diff --git a/text-objects.c b/text-objects.c
index 9f646dc..a65d46c 100644
--- a/text-objects.c
+++ b/text-objects.c
@@ -221,6 +221,11 @@ Filerange text_object_line(Text *txt, size_t pos) {
return r;
}
+Filerange text_object_line_inner(Text *txt, size_t pos) {
+ Filerange r = text_object_line(txt, pos);
+ return text_range_inner(txt, &r);
+}
+
Filerange text_object_sentence(Text *txt, size_t pos) {
Filerange r;
r.start = text_sentence_prev(txt, pos);
@@ -346,3 +351,15 @@ bool text_range_is_linewise(Text *txt, Filerange *r) {
r->start == text_line_begin(txt, r->start) &&
r->end == text_line_begin(txt, r->end);
}
+
+Filerange text_range_inner(Text *txt, Filerange *rin) {
+ char c;
+ Filerange r = *rin;
+ Iterator it = text_iterator_get(txt, rin->start);
+ while (text_iterator_byte_get(&it, &c) && isspace((unsigned char)c))
+ text_iterator_byte_next(&it, NULL);
+ r.start = it.pos;
+ it = text_iterator_get(txt, rin->end);
+ do r.end = it.pos; while (text_iterator_byte_prev(&it, &c) && isspace((unsigned char)c));
+ return r;
+}
diff --git a/text-objects.h b/text-objects.h
index 1ff728a..5781b51 100644
--- a/text-objects.h
+++ b/text-objects.h
@@ -26,6 +26,7 @@ Filerange text_object_longword(Text*, size_t pos);
Filerange text_object_longword_outer(Text*, size_t pos);
Filerange text_object_line(Text*, size_t pos);
+Filerange text_object_line_inner(Text*, size_t pos);
Filerange text_object_sentence(Text*, size_t pos);
Filerange text_object_paragraph(Text*, size_t pos);
@@ -45,6 +46,8 @@ Filerange text_object_backtick(Text*, size_t pos);
/* extend a range to cover whole lines */
Filerange text_range_linewise(Text*, Filerange*);
+/* trim leading and trailing white spaces from range */
+Filerange text_range_inner(Text*, Filerange*);
/* test whether a given range covers whole lines */
bool text_range_is_linewise(Text*, Filerange*);
diff --git a/vis.c b/vis.c
index cb80a97..d6cbdbb 100644
--- a/vis.c
+++ b/vis.c
@@ -266,6 +266,8 @@ enum {
TEXT_OBJ_INNER_ENTIRE,
TEXT_OBJ_OUTER_FUNCTION,
TEXT_OBJ_INNER_FUNCTION,
+ TEXT_OBJ_OUTER_LINE,
+ TEXT_OBJ_INNER_LINE,
};
static TextObject textobjs[] = {
@@ -293,6 +295,8 @@ static TextObject textobjs[] = {
[TEXT_OBJ_INNER_ENTIRE] = { text_object_entire_inner, },
[TEXT_OBJ_OUTER_FUNCTION] = { text_object_function, },
[TEXT_OBJ_INNER_FUNCTION] = { text_object_function_inner, },
+ [TEXT_OBJ_OUTER_LINE] = { text_object_line, },
+ [TEXT_OBJ_INNER_LINE] = { text_object_line_inner, },
};
/** functions to be called from keybindings */