From 010dcd60ffda37027908f2a0b20c751b83ca975e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 24 Aug 2016 11:03:34 +0200 Subject: vis: implement gJ like behavior The behavior is not exactly the same because vim preserves any existing white spaces wihle we remove existing ones but do not insert additional ones. The vim behavior (essentially only deleating new lines) can be achived using something like: :x/\n/d Close #374 --- vis-operators.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'vis-operators.c') diff --git a/vis-operators.c b/vis-operators.c index 3954920..b7b2335 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -193,13 +193,15 @@ static size_t op_join(Vis *vis, Text *txt, OperatorContext *c) { pos = line_prev; } + size_t len = c->arg->s ? strlen(c->arg->s) : 0; + do { prev_pos = pos; size_t end = text_line_start(txt, pos); pos = text_char_next(txt, text_line_finish(txt, text_line_prev(txt, end))); if (pos >= c->range.start && end > pos) { text_delete(txt, pos, end - pos); - text_insert(txt, pos, " ", 1); + text_insert(txt, pos, c->arg->s, len); if (!mark) mark = text_mark_set(txt, pos); } else { @@ -246,6 +248,9 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) { vis->action.arg.i = id; id = VIS_OP_PUT_AFTER; break; + case VIS_OP_JOIN: + vis->action.arg.s = va_arg(ap, char*); + break; case VIS_OP_FILTER: vis->action.arg.s = va_arg(ap, char*); /* fall through */ -- cgit v1.2.3