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 --- main.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 26a9390..485478e 100644 --- a/main.c +++ b/main.c @@ -239,8 +239,8 @@ enum { VIS_ACTION_INSERT_LINE_START, VIS_ACTION_OPEN_LINE_ABOVE, VIS_ACTION_OPEN_LINE_BELOW, - VIS_ACTION_JOIN_LINE_BELOW, VIS_ACTION_JOIN_LINES, + VIS_ACTION_JOIN_LINES_TRIM, VIS_ACTION_PROMPT_SHOW, VIS_ACTION_REPEAT, VIS_ACTION_SELECTION_FLIP, @@ -857,15 +857,15 @@ static const KeyAction vis_action[] = { "Begin a new line below the cursor", openline, { .i = +1 } }, - [VIS_ACTION_JOIN_LINE_BELOW] = { - "join-line-below", - "Join line(s)", - join, { .i = VIS_MOVE_LINE_NEXT }, - }, [VIS_ACTION_JOIN_LINES] = { "join-lines", "Join selected lines", - operator, { .i = VIS_OP_JOIN } + join, { .s = " " } + }, + [VIS_ACTION_JOIN_LINES_TRIM] = { + "join-lines-trim", + "Join selected lines, remove white space", + join, { .s = "" } }, [VIS_ACTION_PROMPT_SHOW] = { "prompt-show", @@ -1973,11 +1973,14 @@ static const char *openline(Vis *vis, const char *keys, const Arg *arg) { } static const char *join(Vis *vis, const char *keys, const Arg *arg) { - int count = vis_count_get_default(vis, 0); - if (count) - vis_count_set(vis, count-1); - vis_operator(vis, VIS_OP_JOIN); - vis_motion(vis, arg->i); + bool normal = (vis_mode_get(vis) == VIS_MODE_NORMAL); + vis_operator(vis, VIS_OP_JOIN, arg->s); + if (normal) { + int count = vis_count_get_default(vis, 0); + if (count) + vis_count_set(vis, count-1); + vis_motion(vis, VIS_MOVE_LINE_NEXT); + } return keys; } -- cgit v1.2.3