From b37f9e461798ba77e19ab20d7ca18555d1171e19 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 19 Oct 2014 12:24:38 +0200 Subject: Toggle case operator In vim, :set tildeop to get this behaviour --- config.def.h | 1 + vis.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 9cd686a..832a975 100644 --- a/config.def.h +++ b/config.def.h @@ -217,6 +217,7 @@ static KeyBinding vis_operators[] = { { { NONE('>') }, operator, { .i = OP_SHIFT_RIGHT } }, { { NONE('<') }, operator, { .i = OP_SHIFT_LEFT } }, { { NONE('g'), NONE('U') }, changecase, { .i = +1 } }, + { { NONE('~') }, changecase, { .i = 0 } }, { { NONE('g'), NONE('u') }, changecase, { .i = -1 } }, { /* empty last element, array terminator */ }, }; diff --git a/vis.c b/vis.c index c8531e4..f82ab89 100644 --- a/vis.c +++ b/vis.c @@ -616,7 +616,11 @@ static void op_case_change(OperatorContext *c) { size_t rem = len; for (char *cur = buf; rem > 0; cur++, rem--) { if (isascii((unsigned char)*cur)) { - if (c->arg->i > 0) + if (c->arg->i == 0) { + *cur = islower((unsigned char)*cur) ? + toupper((unsigned char)*cur) : + tolower((unsigned char)*cur) ; + } else if (c->arg->i > 0) *cur = toupper((unsigned char)*cur); else *cur = tolower((unsigned char)*cur); -- cgit v1.2.3