[PATCH] vi: implement :p (go to previous file)

Dennis Groenen tj.groenen at gmail.com
Wed Jan 25 21:04:55 UTC 2012


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 <tj.groenen at gmail.com>
---
 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-vi-implement-p-go-to-previous-file.patch
Type: text/x-patch
Size: 1126 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20120125/0bb6c876/attachment.bin>


More information about the busybox mailing list