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
22
33 VIM USER MANUAL - by Bram Moolenaar
44
@@ -268,14 +268,15 @@ when it doesn't, append !: >
268268 You cannot `unlet ` script-local variables in | Vim9 | script, only in legacy
269269script.
270270
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:
273274>
274275 vim9script
275276 var counter = 0
276277 def g:GetCount(): number
277- s: counter += 1
278- return s: counter
278+ counter += 1
279+ return counter
279280 enddef
280281
281282 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: >
322323
323324 If you make a mistake and try to assign the wrong type of value you'll get an
324325error: >
325-
326+
326327 age = "Peter"
327328< E1012: Type mismatch; expected number but got string ~
328329
@@ -638,7 +639,7 @@ Make sure that the argument for `normal` is a complete command. Otherwise
638639Vim will run into the end of the argument and silently abort the command. For
639640example, if you start the delete operator, you must give the movement command
640641also. This works: >
641-
642+
642643 normal d$
643644
644645 This does nothing: >
@@ -736,6 +737,8 @@ String manipulation: *string-functions*
736737 fnameescape() escape a file name for use with a Vim command
737738 tr() translate characters from one set to another
738739 strtrans() translate a string to make it printable
740+ keytrans() translate internal keycodes to a form that
741+ can be used by | :map |
739742 tolower() turn a string to lowercase
740743 toupper() turn a string to uppercase
741744 charclass() class of a character
@@ -791,14 +794,16 @@ List manipulation: *list-functions*
791794 reduce() reduce a List to a value
792795 slice() take a slice of a List
793796 sort() sort a List
794- reverse() reverse the order of a List
797+ reverse() reverse the order of a List or Blob
795798 uniq() remove copies of repeated adjacent items
796799 split() split a String into a List
797800 join() join List items into a String
798801 range() return a List with a sequence of numbers
799802 string() String representation of a List
800803 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
802807 max() maximum value in a List
803808 min() minimum value in a List
804809 count() count number of times a value appears in a List
@@ -1035,6 +1040,7 @@ Command line: *command-line-functions*
10351040 getcmdpos() get position of the cursor in the command line
10361041 getcmdscreenpos() get screen position of the cursor in the
10371042 command line
1043+ setcmdline() set the current command line
10381044 setcmdpos() set position of the cursor in the command line
10391045 getcmdtype() return the current command-line type
10401046 getcmdwintype() return the current command-line window type
@@ -1283,6 +1289,7 @@ Popup window: *popup-window-functions*
12831289 popup_filter_yesno() block until 'y' or 'n' is pressed
12841290 popup_getoptions() get current options for a popup
12851291 popup_getpos() get actual position and size of a popup
1292+ popup_findecho() get window ID for popup used for `:echowindow `
12861293 popup_findinfo() get window ID for popup info window
12871294 popup_findpreview() get window ID for popup preview window
12881295 popup_list() get list of all popup window IDs
@@ -1307,6 +1314,14 @@ Prompt Buffer: *promptbuffer-functions*
13071314 prompt_setinterrupt() set interrupt callback for a buffer
13081315 prompt_setprompt() set the prompt text for a buffer
13091316
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+
13101325Text Properties: *text-property-functions*
13111326 prop_add() attach a property at a position
13121327 prop_add_list() attach a property at multiple positions
@@ -1338,6 +1353,7 @@ Various: *various-functions*
13381353 did_filetype() check if a FileType autocommand was used
13391354 eventhandler() check if invoked by an event handler
13401355 getpid() get process ID of Vim
1356+ getscriptinfo() get list of sourced vim scripts
13411357 getimstatus() check if IME status is active
13421358 interrupt() interrupt script execution
13431359 windowsversion() get MS-Windows version
@@ -1349,13 +1365,6 @@ Various: *various-functions*
13491365 undofile() get the name of the undo file
13501366 undotree() return the state of the undo tree
13511367
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-
13591368 shiftwidth() effective value of 'shiftwidth'
13601369
13611370 wordcount() get byte/word/char count of buffer
@@ -1567,7 +1576,7 @@ to "funcref". Example: >
15671576 def Wrong(): string
15681577 return 'Wrong!'
15691578 enddef
1570-
1579+
15711580 var Afunc = g:result == 1 ? Right : Wrong
15721581 echo Afunc()
15731582< Wrong! ~
@@ -1745,9 +1754,10 @@ For further reading see |Dictionaries|.
17451754==============================================================================
17461755*41.9* White space
17471756
1748- Blank lines are allowed and ignored.
1757+ Blank lines are allowed in a script and ignored.
17491758
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".
17511761
17521762Trailing whitespace is often ignored, but not always. One command that
17531763includes 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
18141824examples below. A comment can start on any character position on the line,
18151825but not when it is part of the command, e.g. inside a string.
18161826
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.
18181828This involves some cleverness to make sure double quoted strings are not
18191829recognized as comments (just one reason to prefer | Vim9 | script).
18201830
@@ -1866,13 +1876,16 @@ script executable, and it also works in legacy script: >
18661876*41.12* Fileformat
18671877
18681878The 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+ >
18741884 :setlocal fileformat=unix
18751885
1886+ When using "dos" fileformat, lines are separated with CR-NL, two characters.
1887+ The CR character causes various problems, better avoid this.
1888+
18761889==============================================================================
18771890
18781891Advance information about writing Vim script is in | usr_50.txt | .
0 commit comments