Mercurial > vim
comparison runtime/doc/usr_41.txt @ 856:8cd729851562 v7.0g
updated for version 7.0g
author | vimboss |
---|---|
date | Sun, 30 Apr 2006 18:54:39 +0000 |
parents | a209672376fd |
children | 4bac29d27e2f |
comparison
equal
deleted
inserted
replaced
855:d2a4f08396fe | 856:8cd729851562 |
---|---|
1 *usr_41.txt* For Vim version 7.0f. Last change: 2006 Apr 24 | 1 *usr_41.txt* For Vim version 7.0g. Last change: 2006 Apr 30 |
2 | 2 |
3 VIM USER MANUAL - by Bram Moolenaar | 3 VIM USER MANUAL - by Bram Moolenaar |
4 | 4 |
5 Write a Vim script | 5 Write a Vim script |
6 | 6 |
207 exists() checks. That's not what you want. | 207 exists() checks. That's not what you want. |
208 The exclamation mark ! negates a value. When the value was true, it | 208 The exclamation mark ! negates a value. When the value was true, it |
209 becomes false. When it was false, it becomes true. You can read it as "not". | 209 becomes false. When it was false, it becomes true. You can read it as "not". |
210 Thus "if !exists()" can be read as "if not exists()". | 210 Thus "if !exists()" can be read as "if not exists()". |
211 What Vim calls true is anything that is not zero. Zero is false. | 211 What Vim calls true is anything that is not zero. Zero is false. |
212 Note: | 212 Note: |
213 Vim automatically converts a string to a number when it is looking for | 213 Vim automatically converts a string to a number when it is looking for |
214 a number. When using a string that doesn't start with a digit the | 214 a number. When using a string that doesn't start with a digit the |
215 resulting number is zero. Thus look out for this: > | 215 resulting number is zero. Thus look out for this: > |
216 :if "true" | 216 :if "true" |
217 < The "true" will be interpreted as a zero, thus as false! | 217 < The "true" will be interpreted as a zero, thus as false! |
1074 | 1074 |
1075 A List is an ordered sequence of things. The things can be any kind of value, | 1075 A List is an ordered sequence of things. The things can be any kind of value, |
1076 thus you can make a List of numbers, a List of Lists and even a List of mixed | 1076 thus you can make a List of numbers, a List of Lists and even a List of mixed |
1077 items. To create a List with three strings: > | 1077 items. To create a List with three strings: > |
1078 | 1078 |
1079 :let alist = ['aap', 'mies', 'noot'] | 1079 :let alist = ['aap', 'mies', 'noot'] |
1080 | 1080 |
1081 The List items are enclosed in square brackets and separated by commas. To | 1081 The List items are enclosed in square brackets and separated by commas. To |
1082 create an empty List: > | 1082 create an empty List: > |
1083 | 1083 |
1084 :let alist = [] | 1084 :let alist = [] |
1085 | 1085 |
1086 You can add items to a List with the add() function: > | 1086 You can add items to a List with the add() function: > |
1087 | 1087 |
1088 :let alist = [] | 1088 :let alist = [] |
1089 :call add(alist, 'foo') | 1089 :call add(alist, 'foo') |
1090 :call add(alist, 'bar') | 1090 :call add(alist, 'bar') |
1091 :echo alist | 1091 :echo alist |
1092 < ['foo', 'bar'] ~ | 1092 < ['foo', 'bar'] ~ |
1093 | 1093 |
1096 :echo alist + ['foo', 'bar'] | 1096 :echo alist + ['foo', 'bar'] |
1097 < ['foo', 'bar', 'foo', 'bar'] ~ | 1097 < ['foo', 'bar', 'foo', 'bar'] ~ |
1098 | 1098 |
1099 Or, if you want to extend a List directly: > | 1099 Or, if you want to extend a List directly: > |
1100 | 1100 |
1101 :let alist = ['one'] | 1101 :let alist = ['one'] |
1102 :call extend(alist, ['two', 'three']) | 1102 :call extend(alist, ['two', 'three']) |
1103 :echo alist | 1103 :echo alist |
1104 < ['one', 'two', 'three'] ~ | 1104 < ['one', 'two', 'three'] ~ |
1105 | 1105 |
1106 Notice that using add() will have a different effect: > | 1106 Notice that using add() will have a different effect: > |
1107 | 1107 |
1108 :let alist = ['one'] | 1108 :let alist = ['one'] |
1109 :call add(alist, ['two', 'three']) | 1109 :call add(alist, ['two', 'three']) |
1110 :echo alist | 1110 :echo alist |
1111 < ['one', ['two', 'three']] ~ | 1111 < ['one', ['two', 'three']] ~ |
1112 | 1112 |
1113 The second argument of add() is added as a single item. | 1113 The second argument of add() is added as a single item. |
1153 6 ~ | 1153 6 ~ |
1154 4 ~ | 1154 4 ~ |
1155 | 1155 |
1156 A more useful example, looping over lines in the buffer: > | 1156 A more useful example, looping over lines in the buffer: > |
1157 | 1157 |
1158 :for line in getline(1, 20) | 1158 :for line in getline(1, 20) |
1159 : if line =~ "Date: " | 1159 : if line =~ "Date: " |
1160 : echo matchstr(line, 'Date: \zs.*') | 1160 : echo matchstr(line, 'Date: \zs.*') |
1161 : endif | 1161 : endif |
1162 :endfor | 1162 :endfor |
1163 | 1163 |
1164 This looks into lines 1 to 20 (inclusive) and echoes any date found in there. | 1164 This looks into lines 1 to 20 (inclusive) and echoes any date found in there. |
1165 | 1165 |
1166 | 1166 |
1167 DICTIONARIES | 1167 DICTIONARIES |
1168 | 1168 |
1169 A Dictionary stores key-value pairs. You can quickly lookup a value if you | 1169 A Dictionary stores key-value pairs. You can quickly lookup a value if you |
1170 know the key. A Dictionary is created with curly braces: > | 1170 know the key. A Dictionary is created with curly braces: > |
1171 | 1171 |
1172 :let uk2nl = {'one': 'een', 'two': 'twee', 'three': 'drie'} | 1172 :let uk2nl = {'one': 'een', 'two': 'twee', 'three': 'drie'} |
1173 | 1173 |
1174 Now you can lookup words by putting the key in square brackets: > | 1174 Now you can lookup words by putting the key in square brackets: > |
1175 | 1175 |
1176 :echo uk2nl['two'] | 1176 :echo uk2nl['two'] |
2272 is sourced at startup. A |FuncUndefined| autocommand is defined. The | 2272 is sourced at startup. A |FuncUndefined| autocommand is defined. The |
2273 ":finish" command causes the script to terminate early. | 2273 ":finish" command causes the script to terminate early. |
2274 | 2274 |
2275 2. The user types the BNRead command or presses the <F19> key. The | 2275 2. The user types the BNRead command or presses the <F19> key. The |
2276 BufNetRead() or BufNetWrite() function will be called. | 2276 BufNetRead() or BufNetWrite() function will be called. |
2277 | 2277 |
2278 3. Vim can't find the function and triggers the |FuncUndefined| autocommand | 2278 3. Vim can't find the function and triggers the |FuncUndefined| autocommand |
2279 event. Since the pattern "BufNet*" matches the invoked function, the | 2279 event. Since the pattern "BufNet*" matches the invoked function, the |
2280 command "source fname" will be executed. "fname" will be equal to the name | 2280 command "source fname" will be executed. "fname" will be equal to the name |
2281 of the script, no matter where it is located, because it comes from | 2281 of the script, no matter where it is located, because it comes from |
2282 expanding "<sfile>" (see |expand()|). | 2282 expanding "<sfile>" (see |expand()|). |