diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-08-24 11:03:34 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-08-24 11:13:02 +0200 |
| commit | 010dcd60ffda37027908f2a0b20c751b83ca975e (patch) | |
| tree | 65e0b4f0fd55d5f6d5dc817b39d6c74bebab705f /vis-operators.c | |
| parent | 1cc8afb756839d4e336c1151caecc400ac8d730a (diff) | |
| download | vis-010dcd60ffda37027908f2a0b20c751b83ca975e.tar.gz vis-010dcd60ffda37027908f2a0b20c751b83ca975e.tar.xz | |
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
Diffstat (limited to 'vis-operators.c')
| -rw-r--r-- | vis-operators.c | 7 |
1 files changed, 6 insertions, 1 deletions
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 */ |
