Home Explore Blog CI



neovim

93th chunk of `runtime/doc/vimfn.txt`
50823d2c985dff8c3e1d70f6a6a0dc0e8208c215c24dedd30000000100000fa7
 get an overflow error |E1510|, when the field-width
		or precision will result in a string longer than 1 MB
		(1024*1024 = 1048576) chars.

							*E1500*
		You cannot mix positional and non-positional arguments: >vim
		    echo printf("%s%1$s", "One", "Two")
<		    E1500: Cannot mix positional and non-positional arguments:
		    %s%1$s

							*E1501*
		You cannot skip a positional argument in a format string: >vim
		    echo printf("%3$s%1$s", "One", "Two", "Three")
<		    E1501: format argument 2 unused in $-style format:
		    %3$s%1$s

							*E1502*
		You can re-use a [field-width] (or [precision]) argument: >vim
		    echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
<		    1 at width 2 is: 01

		However, you can't use it as a different type: >vim
		    echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
<		    E1502: Positional argument 2 used as field width reused as
		    different type: long int/int

							*E1503*
		When a positional argument is used, but not the correct number
		or arguments is given, an error is raised: >vim
		    echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
<		    E1503: Positional argument 3 out of bounds: %1$d at width
		    %2$d is: %01$*2$.*3$d

		Only the first error is reported: >vim
		    echo printf("%01$*2$.*3$d %4$d", 1, 2)
<		    E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
		    %4$d

							*E1504*
		A positional argument can be used more than once: >vim
		    echo printf("%1$s %2$s %1$s", "One", "Two")
<		    One Two One

		However, you can't use a different type the second time: >vim
		    echo printf("%1$s %2$s %1$d", "One", "Two")
<		    E1504: Positional argument 1 type used inconsistently:
		    int/string

							*E1505*
		Various other errors that lead to a format string being
		wrongly formatted lead to: >vim
		    echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
<		    E1505: Invalid format specifier: %1$d at width %2$d is:
		    %01$*2$.3$d

							*E1507*
		This internal error indicates that the logic to parse a
		positional format argument ran into a problem that couldn't be
		otherwise reported.  Please file a bug against Vim if you run
		into this, copying the exact format string and parameters that
		were used.

                Parameters: ~
                  • {fmt} (`string`)
                  • {expr1} (`any?`)

                Return: ~
                  (`string`)

prompt_getprompt({buf})                                     *prompt_getprompt()*
		Returns the effective prompt text for buffer {buf}.  {buf} can
		be a buffer name or number.  See |prompt-buffer|.

		If the buffer doesn't exist or isn't a prompt buffer, an empty
		string is returned.

                Parameters: ~
                  • {buf} (`integer|string`)

                Return: ~
                  (`any`)

prompt_setcallback({buf}, {expr})                         *prompt_setcallback()*
		Set prompt callback for buffer {buf} to {expr}.  When {expr}
		is an empty string the callback is removed.  This has only
		effect if {buf} has 'buftype' set to "prompt".

		The callback is invoked when pressing Enter.  The current
		buffer will always be the prompt buffer.  A new line for a
		prompt is added before invoking the callback, thus the prompt
		for which the callback was invoked will be in the last but one
		line.
		If the callback wants to add text to the buffer, it must
		insert it above the last line, since that is where the current
		prompt is.  This can also be done asynchronously.
		The callback is invoked with one argument, which is the text
		that was entered at the prompt.  This can be an empty string
		if the user only typed Enter.
		Example: >vim
		   func s:TextEntered(text)
		     if a:text == 'exit' || a:text == 'quit'
		       stopinsert
		       " Reset 'modified' to allow the buffer to be closed.
		       " We assume there is nothing useful to be saved.
		       set nomodified
		       close
		     else
		       " Do something useful with "a:text".

Title: printf Error Handling and Prompt Functions
Summary
This section details various error conditions encountered while using the `printf` function in Vim, including overflow errors, mixing positional and non-positional arguments, skipping positional arguments, and type inconsistencies. It also describes the `prompt_getprompt()` function, which retrieves the effective prompt text for a specified buffer, and the `prompt_setcallback()` function, which sets a callback function to be invoked when the user presses Enter in a prompt buffer.