of which may be omitted:
Key Default Description ~
prompt "" Same as {prompt} in the first form.
default "" Same as {text} in the first form.
completion nothing Same as {completion} in the first form.
cancelreturn "" The value returned when the dialog is
cancelled.
highlight nothing Highlight handler: |Funcref|.
The highlighting set with |:echohl| is used for the prompt.
The input is entered just like a command-line, with the same
editing commands and mappings. There is a separate history
for lines typed for input().
Example: >vim
if input("Coffee or beer? ") == "beer"
echo "Cheers!"
endif
<
If the optional {text} argument is present and not empty, this
is used for the default reply, as if the user typed this.
Example: >vim
let color = input("Color? ", "white")
< The optional {completion} argument specifies the type of
completion supported for the input. Without it completion is
not performed. The supported completion types are the same as
that can be supplied to a user-defined command using the
"-complete=" argument. Refer to |:command-completion| for
more information. Example: >vim
let fname = input("File: ", "", "file")
< *input()-highlight* *E5400* *E5402*
The optional `highlight` key allows specifying function which
will be used for highlighting user input. This function
receives user input as its only argument and must return
a list of 3-tuples [hl_start_col, hl_end_col + 1, hl_group]
where
hl_start_col is the first highlighted column,
hl_end_col is the last highlighted column (+ 1!),
hl_group is |:hi| group used for highlighting.
*E5403* *E5404* *E5405* *E5406*
Both hl_start_col and hl_end_col + 1 must point to the start
of the multibyte character (highlighting must not break
multibyte characters), hl_end_col + 1 may be equal to the
input length. Start column must be in range [0, len(input)),
end column must be in range (hl_start_col, len(input)],
sections must be ordered so that next hl_start_col is greater
then or equal to previous hl_end_col.
Example (try some input with parentheses): >vim
highlight RBP1 guibg=Red ctermbg=red
highlight RBP2 guibg=Yellow ctermbg=yellow
highlight RBP3 guibg=Green ctermbg=green
highlight RBP4 guibg=Blue ctermbg=blue
let g:rainbow_levels = 4
function! RainbowParens(cmdline)
let ret = []
let i = 0
let lvl = 0
while i < len(a:cmdline)
if a:cmdline[i] is# '('
call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)])
let lvl += 1
elseif a:cmdline[i] is# ')'
let lvl -= 1
call add(ret, [i, i + 1, 'RBP' .. ((lvl % g:rainbow_levels) + 1)])
endif
let i += 1
endwhile
return ret
endfunction
call input({'prompt':'>','highlight':'RainbowParens'})
<
Highlight function is called at least once for each new
displayed input string, before command-line is redrawn. It is
expected that function is pure for the duration of one input()
call, i.e. it produces the same output for the same input, so
output may be memoized. Function is run like under |:silent|
modifier. If the function causes any errors, it will be
skipped for the duration of the current input() call.
Highlighting is disabled if command-line contains arabic
characters.
NOTE: This function must not be used in a startup file, for
the versions that only run in GUI mode (e.g., the Win32 GUI).
Note: When input() is called from within a mapping it will
consume remaining characters from that mapping, because a
mapping is handled like the characters were typed.
Use |inputsave()| before input() and |inputrestore()|
after input() to avoid that. Another solution is to avoid
that further characters follow in the mapping, e.g., by using
|:execute| or |:normal|.
Example with a mapping: >vim
nmap \x