import { fn } from "https://deno.land/x/ddu_vim@v1.13.0/deps.ts";
const { exists } = fn;
The result is a Number, which is |TRUE| if {expr} is defined, zero otherwise.
For checking for a supported feature use |has()|. For checking if a file exists use |filereadable()|.
The {expr} argument is a string, which contains one of these: &option-name Vim option (only checks if it exists, not if it really works) +option-name Vim option that works. $ENVNAME environment variable (could also be done by comparing with an empty string) *funcname built-in function (see |functions|) or user defined function (see |user-functions|). Also works for a variable that is a Funcref. varname internal variable (see |internal-variables|). Also works for |curly-braces-names|, |Dictionary| entries, |List| items, etc. Beware that evaluating an index may cause an error message for an invalid expression. E.g.: :let l = [1, 2, 3] :echo exists("l[5]") 0 :echo exists("l[xx]") E121: Undefined variable: xx 0 :cmdname Ex command: built-in command, user command or command modifier |:command|. Returns: 1 for match with start of a command 2 full match with a command 3 matches several user commands To check for a supported command always check the return value to be 2. :2match The |:2match| command. :3match The |:3match| command. #event autocommand defined for this event #event#pattern autocommand defined for this event and pattern (the pattern is taken literally and compared to the autocommand patterns character by character) #group autocommand group exists #group#event autocommand defined for this group and event. #group#event#pattern autocommand defined for this group, event and pattern. ##event autocommand for this event is supported.
Examples: exists("&mouse") exists("$HOSTNAME") exists("strftime") exists("s:MyFunc") exists("bufcount") exists(":Make") exists("#CursorHold") exists("#BufReadPre#.gz") exists("#filetypeindent") exists("#filetypeindent#FileType") exists("#filetypeindent#FileType#") exists("##ColorScheme") There must be no space between the symbol (&/$/* /#) and the name. There must be no extra characters after the name, although in a few cases this is ignored. That may become more strict in the future, thus don't count on it! Working example: exists(":make") NOT working example: exists(":make install")
Note that the argument must be a string, not the name of the variable itself. For example: exists(bufcount) This doesn't check for existence of the "bufcount" variable, but gets the value of "bufcount", and checks if that exists.