1
- *usr_41.txt* For Vim version 9.0. Last change: 2022 Jun 10
1
+ *usr_41.txt* For Vim version 9.0. Last change: 2022 Oct 07
2
2
3
3
VIM USER MANUAL - by Bram Moolenaar
4
4
@@ -268,14 +268,15 @@ when it doesn't, append !: >
268
268
You cannot `unlet ` script-local variables in | Vim9 | script, only in legacy
269
269
script.
270
270
271
- When a script finishes, the local variables declared there will not be
272
- deleted. Functions defined in the script can use them. Example:
271
+ When a script has been processed to the end, the local variables declared
272
+ there will not be deleted. Functions defined in the script can use them.
273
+ Example:
273
274
>
274
275
vim9script
275
276
var counter = 0
276
277
def g:GetCount(): number
277
- s: counter += 1
278
- return s: counter
278
+ counter += 1
279
+ return counter
279
280
enddef
280
281
281
282
Every time you call the function it will return the next count: >
@@ -322,7 +323,7 @@ want to give the variable a value yet, you need to specify the type: >
322
323
323
324
If you make a mistake and try to assign the wrong type of value you'll get an
324
325
error: >
325
-
326
+
326
327
age = "Peter"
327
328
< E1012: Type mismatch; expected number but got string ~
328
329
@@ -638,7 +639,7 @@ Make sure that the argument for `normal` is a complete command. Otherwise
638
639
Vim will run into the end of the argument and silently abort the command. For
639
640
example, if you start the delete operator, you must give the movement command
640
641
also. This works: >
641
-
642
+
642
643
normal d$
643
644
644
645
This does nothing: >
@@ -736,6 +737,8 @@ String manipulation: *string-functions*
736
737
fnameescape() escape a file name for use with a Vim command
737
738
tr() translate characters from one set to another
738
739
strtrans() translate a string to make it printable
740
+ keytrans() translate internal keycodes to a form that
741
+ can be used by | :map |
739
742
tolower() turn a string to lowercase
740
743
toupper() turn a string to uppercase
741
744
charclass() class of a character
@@ -791,14 +794,16 @@ List manipulation: *list-functions*
791
794
reduce() reduce a List to a value
792
795
slice() take a slice of a List
793
796
sort() sort a List
794
- reverse() reverse the order of a List
797
+ reverse() reverse the order of a List or Blob
795
798
uniq() remove copies of repeated adjacent items
796
799
split() split a String into a List
797
800
join() join List items into a String
798
801
range() return a List with a sequence of numbers
799
802
string() String representation of a List
800
803
call() call a function with List as arguments
801
- index() index of a value in a List
804
+ index() index of a value in a List or Blob
805
+ indexof() index in a List or Blob where an expression
806
+ evaluates to true
802
807
max() maximum value in a List
803
808
min() minimum value in a List
804
809
count() count number of times a value appears in a List
@@ -1035,6 +1040,7 @@ Command line: *command-line-functions*
1035
1040
getcmdpos() get position of the cursor in the command line
1036
1041
getcmdscreenpos() get screen position of the cursor in the
1037
1042
command line
1043
+ setcmdline() set the current command line
1038
1044
setcmdpos() set position of the cursor in the command line
1039
1045
getcmdtype() return the current command-line type
1040
1046
getcmdwintype() return the current command-line window type
@@ -1283,6 +1289,7 @@ Popup window: *popup-window-functions*
1283
1289
popup_filter_yesno() block until 'y' or 'n' is pressed
1284
1290
popup_getoptions() get current options for a popup
1285
1291
popup_getpos() get actual position and size of a popup
1292
+ popup_findecho() get window ID for popup used for `:echowindow `
1286
1293
popup_findinfo() get window ID for popup info window
1287
1294
popup_findpreview() get window ID for popup preview window
1288
1295
popup_list() get list of all popup window IDs
@@ -1307,6 +1314,14 @@ Prompt Buffer: *promptbuffer-functions*
1307
1314
prompt_setinterrupt() set interrupt callback for a buffer
1308
1315
prompt_setprompt() set the prompt text for a buffer
1309
1316
1317
+ Registers: *register-functions*
1318
+ getreg() get contents of a register
1319
+ getreginfo() get information about a register
1320
+ getregtype() get type of a register
1321
+ setreg() set contents and type of a register
1322
+ reg_executing() return the name of the register being executed
1323
+ reg_recording() return the name of the register being recorded
1324
+
1310
1325
Text Properties: *text-property-functions*
1311
1326
prop_add() attach a property at a position
1312
1327
prop_add_list() attach a property at multiple positions
@@ -1338,6 +1353,7 @@ Various: *various-functions*
1338
1353
did_filetype() check if a FileType autocommand was used
1339
1354
eventhandler() check if invoked by an event handler
1340
1355
getpid() get process ID of Vim
1356
+ getscriptinfo() get list of sourced vim scripts
1341
1357
getimstatus() check if IME status is active
1342
1358
interrupt() interrupt script execution
1343
1359
windowsversion() get MS-Windows version
@@ -1349,13 +1365,6 @@ Various: *various-functions*
1349
1365
undofile() get the name of the undo file
1350
1366
undotree() return the state of the undo tree
1351
1367
1352
- getreg() get contents of a register
1353
- getreginfo() get information about a register
1354
- getregtype() get type of a register
1355
- setreg() set contents and type of a register
1356
- reg_executing() return the name of the register being executed
1357
- reg_recording() return the name of the register being recorded
1358
-
1359
1368
shiftwidth() effective value of 'shiftwidth'
1360
1369
1361
1370
wordcount() get byte/word/char count of buffer
@@ -1567,7 +1576,7 @@ to "funcref". Example: >
1567
1576
def Wrong(): string
1568
1577
return 'Wrong!'
1569
1578
enddef
1570
-
1579
+
1571
1580
var Afunc = g:result == 1 ? Right : Wrong
1572
1581
echo Afunc()
1573
1582
< Wrong! ~
@@ -1745,9 +1754,10 @@ For further reading see |Dictionaries|.
1745
1754
==============================================================================
1746
1755
*41.9* White space
1747
1756
1748
- Blank lines are allowed and ignored.
1757
+ Blank lines are allowed in a script and ignored.
1749
1758
1750
- Leading whitespace characters (blanks and TABs) are always ignored.
1759
+ Leading whitespace characters (blanks and TABs) are ignored, except when using
1760
+ | :let-heredoc | without "trim".
1751
1761
1752
1762
Trailing whitespace is often ignored, but not always. One command that
1753
1763
includes it is `map ` . You have to watch out for that, it can cause hard to
@@ -1814,7 +1824,7 @@ is ignored, except for commands that don't consider comments, as shown in
1814
1824
examples below. A comment can start on any character position on the line,
1815
1825
but not when it is part of the command, e.g. inside a string.
1816
1826
1817
- The character " (the double quote mark) starts a comment in legacy script.
1827
+ The character " (the double quote mark) starts a comment in legacy script.
1818
1828
This involves some cleverness to make sure double quoted strings are not
1819
1829
recognized as comments (just one reason to prefer | Vim9 | script).
1820
1830
@@ -1866,13 +1876,16 @@ script executable, and it also works in legacy script: >
1866
1876
*41.12* Fileformat
1867
1877
1868
1878
The end-of-line character depends on the system. For Vim scripts it is
1869
- recommended to always use the Unix fileformat. This also works on any other
1870
- system. That way you can copy your Vim scripts from MS-Windows to Unix and
1871
- they still work. See | :source_crnl | . To be sure it is set right, do this
1872
- before writing the file: >
1873
-
1879
+ recommended to always use the Unix fileformat. Lines are then separated with
1880
+ the Newline character. This also works on any other system. That way you can
1881
+ copy your Vim scripts from MS-Windows to Unix and they still work. See
1882
+ | :source_crnl | . To be sure it is set right, do this before writing the file:
1883
+ >
1874
1884
:setlocal fileformat=unix
1875
1885
1886
+ When using "dos" fileformat, lines are separated with CR-NL, two characters.
1887
+ The CR character causes various problems, better avoid this.
1888
+
1876
1889
==============================================================================
1877
1890
1878
1891
Advance information about writing Vim script is in | usr_50.txt | .
0 commit comments