Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
5746:798d83d15327 | 5747:ddc3f32a4b21 |
---|---|
325 :call filter(list, 'v:val !~ "x"') " remove items with an 'x' | 325 :call filter(list, 'v:val !~ "x"') " remove items with an 'x' |
326 | 326 |
327 Changing the order of items in a list: > | 327 Changing the order of items in a list: > |
328 :call sort(list) " sort a list alphabetically | 328 :call sort(list) " sort a list alphabetically |
329 :call reverse(list) " reverse the order of items | 329 :call reverse(list) " reverse the order of items |
330 :call uniq(sort(list)) " sort and remove duplicates | |
330 | 331 |
331 | 332 |
332 For loop ~ | 333 For loop ~ |
333 | 334 |
334 The |:for| loop executes commands for each item in a list. A variable is set | 335 The |:for| loop executes commands for each item in a list. A variable is set |
2003 to chars in {tostr} | 2004 to chars in {tostr} |
2004 trunc( {expr}) Float truncate Float {expr} | 2005 trunc( {expr}) Float truncate Float {expr} |
2005 type( {name}) Number type of variable {name} | 2006 type( {name}) Number type of variable {name} |
2006 undofile( {name}) String undo file name for {name} | 2007 undofile( {name}) String undo file name for {name} |
2007 undotree() List undo file tree | 2008 undotree() List undo file tree |
2009 uniq( {list} [, {func} [, {dict}]]) | |
2010 List remove adjacent duplicates from a list | |
2008 values( {dict}) List values in {dict} | 2011 values( {dict}) List values in {dict} |
2009 virtcol( {expr}) Number screen column of cursor or mark | 2012 virtcol( {expr}) Number screen column of cursor or mark |
2010 visualmode( [expr]) String last visual mode used | 2013 visualmode( [expr]) String last visual mode used |
2011 wildmenumode() Number whether 'wildmenu' mode is active | 2014 wildmenumode() Number whether 'wildmenu' mode is active |
2012 winbufnr( {nr}) Number buffer number of window {nr} | 2015 winbufnr( {nr}) Number buffer number of window {nr} |
5486 < -1.026517 | 5489 < -1.026517 |
5487 {only available when compiled with the |+float| feature} | 5490 {only available when compiled with the |+float| feature} |
5488 | 5491 |
5489 | 5492 |
5490 sort({list} [, {func} [, {dict}]]) *sort()* *E702* | 5493 sort({list} [, {func} [, {dict}]]) *sort()* *E702* |
5491 Sort the items in {list} in-place. Returns {list}. If you | 5494 Sort the items in {list} in-place. Returns {list}. |
5492 want a list to remain unmodified make a copy first: > | 5495 |
5496 If you want a list to remain unmodified make a copy first: > | |
5493 :let sortedlist = sort(copy(mylist)) | 5497 :let sortedlist = sort(copy(mylist)) |
5494 < Uses the string representation of each item to sort on. | 5498 < Uses the string representation of each item to sort on. |
5495 Numbers sort after Strings, |Lists| after Numbers. | 5499 Numbers sort after Strings, |Lists| after Numbers. |
5496 For sorting text in the current buffer use |:sort|. | 5500 For sorting text in the current buffer use |:sort|. |
5501 | |
5497 When {func} is given and it is one then case is ignored. | 5502 When {func} is given and it is one then case is ignored. |
5498 {dict} is for functions with the "dict" attribute. It will be | |
5499 used to set the local variable "self". |Dictionary-function| | |
5500 When {func} is a |Funcref| or a function name, this function | 5503 When {func} is a |Funcref| or a function name, this function |
5501 is called to compare items. The function is invoked with two | 5504 is called to compare items. The function is invoked with two |
5502 items as argument and must return zero if they are equal, 1 or | 5505 items as argument and must return zero if they are equal, 1 or |
5503 bigger if the first one sorts after the second one, -1 or | 5506 bigger if the first one sorts after the second one, -1 or |
5504 smaller if the first one sorts before the second one. | 5507 smaller if the first one sorts before the second one. |
5508 | |
5509 {dict} is for functions with the "dict" attribute. It will be | |
5510 used to set the local variable "self". |Dictionary-function| | |
5511 | |
5512 Also see |uniq()|. | |
5513 | |
5505 Example: > | 5514 Example: > |
5506 func MyCompare(i1, i2) | 5515 func MyCompare(i1, i2) |
5507 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 | 5516 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 |
5508 endfunc | 5517 endfunc |
5509 let sortedlist = sort(mylist, "MyCompare") | 5518 let sortedlist = sort(mylist, "MyCompare") |
6166 first write has number 1, the last one the | 6175 first write has number 1, the last one the |
6167 "save_last" mentioned above. | 6176 "save_last" mentioned above. |
6168 "alt" Alternate entry. This is again a List of undo | 6177 "alt" Alternate entry. This is again a List of undo |
6169 blocks. Each item may again have an "alt" | 6178 blocks. Each item may again have an "alt" |
6170 item. | 6179 item. |
6180 | |
6181 uniq({list} [, {func} [, {dict}]]) *uniq()* *E882* | |
6182 Remove second and succeeding copies of repeated adjacent | |
6183 {list} items in-place. Returns {list}. If you want a list | |
6184 to remain unmodified make a copy first: > | |
6185 :let newlist = uniq(copy(mylist)) | |
6186 < The default compare function uses the string representation of | |
6187 each item. For the use of {func} and {dict} see |sort()|. | |
6171 | 6188 |
6172 values({dict}) *values()* | 6189 values({dict}) *values()* |
6173 Return a |List| with all the values of {dict}. The |List| is | 6190 Return a |List| with all the values of {dict}. The |List| is |
6174 in arbitrary order. | 6191 in arbitrary order. |
6175 | 6192 |