diff options
-rw-r--r-- | src/ex_cmds.c | 29 | ||||
-rw-r--r-- | src/ex_docmd.c | 3 | ||||
-rw-r--r-- | src/ex_docmd.h | 1 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 32 insertions, 3 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 02bb65f13e..e3d02357e1 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -3653,6 +3653,35 @@ void do_sub(exarg_T *eap) endcolumn = (curwin->w_curswant == MAXCOL); } + // Recognize ":%s/\n//" and turn it into a join command, which is much + // more efficient. + // TODO: find a generic solution to make line-joining operations more + // efficient, avoid allocating a string that grows in size. + if (strcmp((const char *)pat, "\\n") == 0 + && strlen((const char *)pat) == 2 + && *sub == NUL + && (*cmd == NUL || (cmd[1] == NUL + && (*cmd == 'g' + || *cmd == 'l' + || *cmd == 'p' + || *cmd == '#')))) { + curwin->w_cursor.lnum = eap->line1; + if (*cmd == 'l') { + eap->flags = EXFLAG_LIST; + } else if (*cmd == '#') { + eap->flags = EXFLAG_NR; + } else if (*cmd == 'p') { + eap->flags = EXFLAG_PRINT; + } + + do_join(eap->line2 - eap->line1 + 1, FALSE, TRUE, FALSE); + sub_nlines = sub_nsubs = eap->line2 - eap->line1 + 1; + do_sub_msg(FALSE); + ex_may_print(eap); + + return; + } + /* * Find trailing options. When '&' is used, keep old options. */ diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 542a49f465..225bc747b8 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -182,7 +182,6 @@ static void ex_winpos(exarg_T *eap); static void ex_operators(exarg_T *eap); static void ex_put(exarg_T *eap); static void ex_copymove(exarg_T *eap); -static void ex_may_print(exarg_T *eap); static void ex_submagic(exarg_T *eap); static void ex_join(exarg_T *eap); static void ex_at(exarg_T *eap); @@ -6906,7 +6905,7 @@ static void ex_copymove(exarg_T *eap) /* * Print the current line if flags were given to the Ex command. */ -static void ex_may_print(exarg_T *eap) +void ex_may_print(exarg_T *eap) { if (eap->flags != 0) { print_line(curwin->w_cursor.lnum, (eap->flags & EXFLAG_NR), diff --git a/src/ex_docmd.h b/src/ex_docmd.h index f9d683d09d..52c5ba8803 100644 --- a/src/ex_docmd.h +++ b/src/ex_docmd.h @@ -23,6 +23,7 @@ char_u *find_nextcmd(char_u *p); char_u *check_nextcmd(char_u *p); char_u *get_command_name(expand_T *xp, int idx); void ex_comclear(exarg_T *eap); +void ex_may_print(exarg_T *eap); void uc_clear(garray_T *gap); char_u *get_user_commands(expand_T *xp, int idx); char_u *get_user_cmd_flags(expand_T *xp, int idx); diff --git a/src/version.c b/src/version.c index 4955dea885..5113ad3e27 100644 --- a/src/version.c +++ b/src/version.c @@ -229,7 +229,7 @@ static int included_patches[] = { //235, //234, //233, - //232, + 232, //231, //230, 229, |