On Di, 24 Jun 2014, Christian Brabandt wrote:

> On Di, 24 Jun 2014, Axel Bender wrote:
> 
> > Does anyone know a UTF-8-aware (respecting $LC_ALL and/or $LANGUAGE) sort 
> > tool for Windows (GNUWin32's doesn't work), preferably a working GNU sort 
> > that does the job? [OFF-TOPIC]
> 
> Cygwin, Msys, Interix? Not sure, but not sure, which one does support 
> UTF-8. I can't believe GNUWin32 doesn't support UTF-8.
> 
> > It would be a nice idea [NO LONGER OFF-TOPIC] to add the possibility to add 
> > sort columns (like in GNU's --key=<field>.<char>) to vim's :sort command. 
> > Doing so would the first problem above obsolete...
> 
> It should be possible, to Script something using viml. Perhaps some of 
> the Viml librariesน provide such a possibility already?

While being at the topic of :sort, I noticed there seems to be a bug 
with :sort, that it will try to sort, even when there would be nothing 
to sort.

Using the example from Axel, and do :sort! r /foobar/
You'll notice, Vim will randomly sort your buffer. So here is a patch, 
that skips sorting, if the RE doesn't match anything (this might also be 
caused by an illegal pattern) and will therefore not randomly change 
your buffer. So here is a patch.

Best,
Christian
-- 
Wenn man alt ist, denkt man über die weltlichen Dinge anders, als da man 
jung war.
                -- Johann Wolfgang von Goethe (zu Eckermann)

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -366,6 +366,7 @@ ex_sort(eap)
     colnr_T	end_col;
     int		sort_oct;		/* sort on octal number */
     int		sort_hex;		/* sort on hex number */
+    int		skip_sort = 0;
 
     /* Sorting one line is really quick! */
     if (count <= 1)
@@ -495,8 +496,11 @@ ex_sort(eap)
 	    if (s > p && s[-1] == '-')
 		--s;  /* include preceding negative sign */
 	    if (*s == NUL)
+	    {
 		/* empty line should sort before any number */
 		nrs[lnum - eap->line1].start_col_nr = -MAXLNUM;
+		skip_sort += 1;
+	    }
 	    else
 		vim_str2nr(s, NULL, NULL, sort_oct, sort_hex,
 				  &nrs[lnum - eap->line1].start_col_nr, NULL);
@@ -507,6 +511,7 @@ ex_sort(eap)
 	    /* Store the column to sort at. */
 	    nrs[lnum - eap->line1].start_col_nr = start_col;
 	    nrs[lnum - eap->line1].end_col_nr = end_col;
+	    skip_sort += (end_col == 0 && start_col == 0 ? 1 : 0);
 	}
 
 	nrs[lnum - eap->line1].lnum = lnum;
@@ -516,6 +521,9 @@ ex_sort(eap)
 	if (got_int)
 	    goto sortend;
     }
+    /* pattern did not match in any line, skip sorting */
+    if (skip_sort == eap->line2)
+	goto sortend;
 
     /* Allocate a buffer that can hold the longest line. */
     sortbuf1 = alloc((unsigned)maxlen + 1);

Raspunde prin e-mail lui