Though I'm not sure whether :p is an official command in the latest vi
release.. Some cheat sheets refer to it as "Go to previous file"though[1].
Please include the patch if you think it is useful.

make bloatcheck:
function                                             old     new   delta
colon                                               3406    3463     +57
.rodata                                           148379  148410     +31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 88/0)               Total: 88 bytes
   text    data     bss     dec     hex filename
 948040    4042    9544  961626   eac5a busybox_old
 948128    4042    9544  961714   eacb2 busybox_unstripped

--Dennis

[1] http://www.lagmonster.org/docs/vi2.html#file

Signed-off-by: Dennis Groenen <[email protected]>
---
 editors/vi.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index 4a2d5d4..ddca9d6 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1111,6 +1111,7 @@ static void colon(char *buf)
                Hit_Return();
        } else if (strncmp(cmd, "quit", i) == 0 // quit
                || strncmp(cmd, "next", i) == 0 // edit next file
+               || strncmp(cmd, "prev", i) == 0 // edit previous file
        ) {
                int n;
                if (useforce) {
@@ -1137,6 +1138,13 @@ static void colon(char *buf)
                        status_line_bold("No more files to edit");
                        goto ret;
                }
+               // are there previous files to edit
+               if (*cmd == 'p' && optind <= 1) {
+                       status_line_bold("No previous files to edit");
+                       goto ret;
+               } else if (*cmd == 'p' && optind > 1) {
+                       optind = optind - 2;
+               }
                editing = 0;
        } else if (strncmp(cmd, "read", i) == 0) {      // read file into text[]
                fn = args;
-- 
1.7.8.4
From 0221708f0f7147c84c8f7288e9c510241d296a4c Mon Sep 17 00:00:00 2001
From: Dennis Groenen <[email protected]>
Date: Sun, 22 Jan 2012 20:15:21 +0100
Subject: [PATCH] vi: implement :p (go to previous file)

---
 editors/vi.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index 4a2d5d4..ddca9d6 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1111,6 +1111,7 @@ static void colon(char *buf)
 		Hit_Return();
 	} else if (strncmp(cmd, "quit", i) == 0 // quit
 	        || strncmp(cmd, "next", i) == 0 // edit next file
+	        || strncmp(cmd, "prev", i) == 0 // edit previous file
 	) {
 		int n;
 		if (useforce) {
@@ -1137,6 +1138,13 @@ static void colon(char *buf)
 			status_line_bold("No more files to edit");
 			goto ret;
 		}
+		// are there previous files to edit
+		if (*cmd == 'p' && optind <= 1) {
+			status_line_bold("No previous files to edit");
+			goto ret;
+		} else if (*cmd == 'p' && optind > 1) {
+			optind = optind - 2;
+		}
 		editing = 0;
 	} else if (strncmp(cmd, "read", i) == 0) {	// read file into text[]
 		fn = args;
-- 
1.7.8.4

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to