Mercurial > vim
diff runtime/doc/eval.txt @ 5747:ddc3f32a4b21 v7.4.218
updated for version 7.4.218
Problem: It's not easy to remove duplicates from a list.
Solution: Add the uniq() function. (LCD)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 25 Mar 2014 18:24:23 +0100 |
parents | 657ade71d395 |
children | c52a655d927d |
line wrap: on
line diff
--- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -327,6 +327,7 @@ examples: > Changing the order of items in a list: > :call sort(list) " sort a list alphabetically :call reverse(list) " reverse the order of items + :call uniq(sort(list)) " sort and remove duplicates For loop ~ @@ -2005,6 +2006,8 @@ trunc( {expr}) Float truncate Float {e type( {name}) Number type of variable {name} undofile( {name}) String undo file name for {name} undotree() List undo file tree +uniq( {list} [, {func} [, {dict}]]) + List remove adjacent duplicates from a list values( {dict}) List values in {dict} virtcol( {expr}) Number screen column of cursor or mark visualmode( [expr]) String last visual mode used @@ -5488,20 +5491,26 @@ sinh({expr}) *sinh()* sort({list} [, {func} [, {dict}]]) *sort()* *E702* - Sort the items in {list} in-place. Returns {list}. If you - want a list to remain unmodified make a copy first: > + Sort the items in {list} in-place. Returns {list}. + + If you want a list to remain unmodified make a copy first: > :let sortedlist = sort(copy(mylist)) < Uses the string representation of each item to sort on. Numbers sort after Strings, |Lists| after Numbers. For sorting text in the current buffer use |:sort|. + When {func} is given and it is one then case is ignored. - {dict} is for functions with the "dict" attribute. It will be - used to set the local variable "self". |Dictionary-function| When {func} is a |Funcref| or a function name, this function is called to compare items. The function is invoked with two items as argument and must return zero if they are equal, 1 or bigger if the first one sorts after the second one, -1 or smaller if the first one sorts before the second one. + + {dict} is for functions with the "dict" attribute. It will be + used to set the local variable "self". |Dictionary-function| + + Also see |uniq()|. + Example: > func MyCompare(i1, i2) return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 @@ -6169,6 +6178,14 @@ undotree() *undotree()* blocks. Each item may again have an "alt" item. +uniq({list} [, {func} [, {dict}]]) *uniq()* *E882* + Remove second and succeeding copies of repeated adjacent + {list} items in-place. Returns {list}. If you want a list + to remain unmodified make a copy first: > + :let newlist = uniq(copy(mylist)) +< The default compare function uses the string representation of + each item. For the use of {func} and {dict} see |sort()|. + values({dict}) *values()* Return a |List| with all the values of {dict}. The |List| is in arbitrary order.