This is consistent with vim's expandtab behavior.

>From nvi2 (Craig Leres):
https://github.com/lichray/nvi2/commit/7d3f43559026e0927032a105b217850feaefec66

I know most of us don't use expandtab but it is helpful when dealing
with a codebase that is space-indented.  Since the option originated
with vim we should be as compatible as possible...

 - todd

Index: docs/USD.doc/vi.man/vi.1
===================================================================
RCS file: /cvs/src/usr.bin/vi/docs/USD.doc/vi.man/vi.1,v
retrieving revision 1.79
diff -u -p -u -r1.79 vi.1
--- docs/USD.doc/vi.man/vi.1    8 Mar 2021 02:47:29 -0000       1.79
+++ docs/USD.doc/vi.man/vi.1    13 Apr 2021 15:44:26 -0000
@@ -2356,8 +2356,12 @@ characters to
 when inserting, replacing or shifting text, autoindenting,
 indenting with
 .Aq Ic control-T ,
-or outdenting with
-.Aq Ic control-D .
+outdenting with
+.Aq Ic control-D ,
+or
+when filtering lines with the
+.Cm !\&
+command.
 .It Cm exrc , ex Bq off
 Read the startup files in the local directory.
 .It Cm extended Bq off
Index: ex/ex_bang.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/ex/ex_bang.c,v
retrieving revision 1.11
diff -u -p -u -r1.11 ex_bang.c
--- ex/ex_bang.c        18 Apr 2017 01:45:35 -0000      1.11
+++ ex/ex_bang.c        13 Apr 2021 15:44:26 -0000
@@ -171,6 +171,10 @@ ex_bang(SCR *sp, EXCMD *cmdp)
        if (!F_ISSET(sp, SC_VI) && !F_ISSET(sp, SC_EX_SILENT))
                (void)ex_puts(sp, "!\n");
 
+       /* Apply expandtab to the new text */
+       if (O_ISSET(sp, O_EXPANDTAB))
+               ex_retab(sp, cmdp);
+
        /*
         * XXX
         * The ! commands never return an error, so that autoprint always
Index: ex/ex_shift.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/ex/ex_shift.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 ex_shift.c
--- ex/ex_shift.c       30 Apr 2020 10:40:21 -0000      1.9
+++ ex/ex_shift.c       13 Apr 2021 15:44:26 -0000
@@ -21,7 +21,7 @@
 
 #include "../common/common.h"
 
-enum which {LEFT, RIGHT};
+enum which {RETAB, LEFT, RIGHT};
 static int shift(SCR *, EXCMD *, enum which);
 
 /*
@@ -48,6 +48,18 @@ ex_shiftr(SCR *sp, EXCMD *cmdp)
 }
 
 /*
+ * ex_retab -- Expand tabs (if enabled)
+ *
+ *
+ * PUBLIC: int ex_retab(SCR *, EXCMD *);
+ */
+int
+ex_retab(SCR *sp, EXCMD *cmdp)
+{
+       return (shift(sp, cmdp, RETAB));
+}
+
+/*
  * shift --
  *     Ex shift support.
  */
@@ -109,7 +121,9 @@ shift(SCR *sp, EXCMD *cmdp, enum which r
                                break;
 
                /* Calculate the new indent amount. */
-               if (rl == RIGHT)
+               if (rl == RETAB)
+                       newcol = oldcol;
+               else if (rl == RIGHT)
                        newcol = oldcol + sw;
                else {
                        newcol = oldcol < sw ? 0 : oldcol - sw;
Index: include/ex_extern.h
===================================================================
RCS file: /cvs/src/usr.bin/vi/include/ex_extern.h,v
retrieving revision 1.16
diff -u -p -u -r1.16 ex_extern.h
--- include/ex_extern.h 27 May 2016 09:18:12 -0000      1.16
+++ include/ex_extern.h 13 Apr 2021 15:44:26 -0000
@@ -76,6 +76,7 @@ int ex_set(SCR *, EXCMD *);
 int ex_shell(SCR *, EXCMD *);
 int ex_exec_proc(SCR *, EXCMD *, char *, const char *, int);
 int proc_wait(SCR *, pid_t, const char *, int, int);
+int ex_retab(SCR *, EXCMD *);
 int ex_shiftl(SCR *, EXCMD *);
 int ex_shiftr(SCR *, EXCMD *);
 int ex_source(SCR *, EXCMD *);

Reply via email to