Home Explore Blog CI



neovim

19th chunk of `runtime/doc/map.txt`
0fbf11cc2adb734c46854d29ba0975120ff246e85c47cdae0000000100000fa3
 /usr/share/vim/vim-7.0/plugin/tohtml.vim ~

See |:verbose-cmd| for more information.

							*E174* *E182*
:com[mand][!] [{attr}...] {cmd} {repl}
			Define a user command.  The name of the command is
			{cmd} and its replacement text is {repl}.  The
			command's attributes (see below) are {attr}.  If the
			command already exists, an error is reported, unless a
			! is specified, in which case the command is
			redefined.  There is one exception: When sourcing a
			script again, a command that was previously defined in
			that script will be silently replaced.


:delc[ommand] {cmd}				*:delc* *:delcommand* *E184*
			Delete the user-defined command {cmd}.

:delc[ommand] -buffer {cmd}					*E1237*
			Delete the user-defined command {cmd} that was defined
			for the current buffer.

:comc[lear]						*:comc* *:comclear*
			Delete all user-defined commands.


Command attributes ~
							*command-attributes*
User-defined commands are treated by Nvim just like any other Ex commands.  They
can have arguments, or have a range specified.  Arguments are subject to
completion as filenames, buffers, etc.  Exactly how this works depends upon the
command's attributes, which are specified when the command is defined.

When defining a user command in a script, it will be able to call functions
local to the script and use mappings local to the script.  When the user
invokes the user command, it will run in the context of the script it was
defined in.  This matters if |<SID>| is used in a command.

There are a number of attributes, split into four categories: argument
handling, completion behavior, range handling, and special cases.  The
attributes are described below, by category.


Argument handling ~
						*E175* *E176* *:command-nargs*
By default, a user defined command will take no arguments (and an error is
reported if any are supplied).  However, it is possible to specify that the
command can take arguments, using the -nargs attribute.  Valid cases are:

	-nargs=0    No arguments are allowed (the default)
	-nargs=1    Exactly one argument is required, it includes spaces
	-nargs=*    Any number of arguments are allowed (0, 1, or many),
		    separated by white space
	-nargs=?    0 or 1 arguments are allowed
	-nargs=+    Arguments must be supplied, but any number are allowed

Arguments are considered to be separated by (unescaped) spaces or tabs in this
context, except when there is one argument, then the white space is part of
the argument.

Note that arguments are used as text, not as expressions.  Specifically,
"s:var" will use the script-local variable in the script where the command was
defined, not where it is invoked!  Example:
    script1.vim: >
	:let s:error = "None"
	:command -nargs=1 Error echoerr <args>
<   script2.vim: >
	:source script1.vim
	:let s:error = "Wrong!"
	:Error s:error
Executing script2.vim will result in "None" being echoed.  Not what you
intended!  Calling a function may be an alternative.

Completion behavior ~
				*:command-completion* *E179* *E180* *E181*
				*:command-complete*
By default, the arguments of user defined commands do not undergo completion.
However, by specifying one or the other of the following attributes, argument
completion can be enabled:

	-complete=arglist	file names in argument list
	-complete=augroup	autocmd groups
	-complete=breakpoint	|:breakadd| suboptions
	-complete=buffer	buffer names
	-complete=color		color schemes
	-complete=command	Ex command (and arguments)
	-complete=compiler	compilers
	-complete=diff_buffer	diff buffer names
	-complete=dir		directory names
	-complete=dir_in_path	directory names in |'cdpath'|
	-complete=environment	environment variable names
	-complete=event		autocommand events
	-complete=expression	Vim expression
	-complete=file		file and directory names
	-complete=file_in_path	file and directory names in |'path'|
	-complete=filetype	filetype names |'filetype'|
	-complete=function	function name
	-complete=help		help subjects
	-complete=highlight	highlight groups

Title: Defining and Managing User-Defined Commands in Vim: Attributes, Argument Handling, and Completion
Summary
This section details how to define, delete, and clear user-defined commands in Vim, as well as how to specify attributes for user-defined commands. It covers argument handling with `-nargs`, completion behavior with `-complete`, range handling, and other special cases. Additionally, it explains how user commands interact with script-local functions and mappings, and how arguments are treated as text rather than expressions.