diff options
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r-- | src/ex_cmds.c | 29 |
1 files changed, 29 insertions, 0 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. */ |