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 /main.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 'main.c')
| -rw-r--r-- | main.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -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; } |
