Mercurial > vim
comparison runtime/doc/map.txt @ 15125:b101b193d5ff v8.1.0573
patch 8.1.0573: cannot redefine user command without ! in same script
commit https://github.com/vim/vim/commit/55d46913084745a48749d7ac4f48930852e1d87e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 8 16:03:28 2018 +0100
patch 8.1.0573: cannot redefine user command without ! in same script
Problem: Cannot redefine user command without ! in same script
Solution: Allow redefining user command without ! in same script, like with
functions.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 08 Dec 2018 16:15:05 +0100 |
parents | 40ef13331e02 |
children | bc1a8d21c811 |
comparison
equal
deleted
inserted
replaced
15124:27c801cca007 | 15125:b101b193d5ff |
---|---|
1221 Define a user command. The name of the command is | 1221 Define a user command. The name of the command is |
1222 {cmd} and its replacement text is {rep}. The command's | 1222 {cmd} and its replacement text is {rep}. The command's |
1223 attributes (see below) are {attr}. If the command | 1223 attributes (see below) are {attr}. If the command |
1224 already exists, an error is reported, unless a ! is | 1224 already exists, an error is reported, unless a ! is |
1225 specified, in which case the command is redefined. | 1225 specified, in which case the command is redefined. |
1226 There is one exception: When sourcing a script again, | |
1227 a command that was previously defined in that script | |
1228 will be silently replaced. | |
1229 | |
1226 | 1230 |
1227 :delc[ommand] {cmd} *:delc* *:delcommand* *E184* | 1231 :delc[ommand] {cmd} *:delc* *:delcommand* *E184* |
1228 Delete the user-defined command {cmd}. | 1232 Delete the user-defined command {cmd}. |
1229 | 1233 |
1230 :comc[lear] *:comc* *:comclear* | 1234 :comc[lear] *:comc* *:comclear* |
1231 Delete all user-defined commands. | 1235 Delete all user-defined commands. |
1232 | 1236 |
1233 Command attributes | 1237 |
1238 Command attributes ~ | |
1234 | 1239 |
1235 User-defined commands are treated by Vim just like any other Ex commands. They | 1240 User-defined commands are treated by Vim just like any other Ex commands. They |
1236 can have arguments, or have a range specified. Arguments are subject to | 1241 can have arguments, or have a range specified. Arguments are subject to |
1237 completion as filenames, buffers, etc. Exactly how this works depends upon the | 1242 completion as filenames, buffers, etc. Exactly how this works depends upon the |
1238 command's attributes, which are specified when the command is defined. | 1243 command's attributes, which are specified when the command is defined. |
1239 | 1244 |
1240 There are a number of attributes, split into four categories: argument | 1245 There are a number of attributes, split into four categories: argument |
1241 handling, completion behavior, range handling, and special cases. The | 1246 handling, completion behavior, range handling, and special cases. The |
1242 attributes are described below, by category. | 1247 attributes are described below, by category. |
1243 | 1248 |
1244 Argument handling *E175* *E176* *:command-nargs* | 1249 |
1245 | 1250 Argument handling ~ |
1251 *E175* *E176* *:command-nargs* | |
1246 By default, a user defined command will take no arguments (and an error is | 1252 By default, a user defined command will take no arguments (and an error is |
1247 reported if any are supplied). However, it is possible to specify that the | 1253 reported if any are supplied). However, it is possible to specify that the |
1248 command can take arguments, using the -nargs attribute. Valid cases are: | 1254 command can take arguments, using the -nargs attribute. Valid cases are: |
1249 | 1255 |
1250 -nargs=0 No arguments are allowed (the default) | 1256 -nargs=0 No arguments are allowed (the default) |
1269 :let s:error = "Wrong!" | 1275 :let s:error = "Wrong!" |
1270 :Error s:error | 1276 :Error s:error |
1271 Executing script2.vim will result in "None" being echoed. Not what you | 1277 Executing script2.vim will result in "None" being echoed. Not what you |
1272 intended! Calling a function may be an alternative. | 1278 intended! Calling a function may be an alternative. |
1273 | 1279 |
1274 Completion behavior *:command-completion* *E179* | 1280 |
1275 *E180* *E181* *:command-complete* | 1281 Completion behavior ~ |
1282 *:command-completion* *E179* *E180* *E181* | |
1283 *:command-complete* | |
1276 By default, the arguments of user defined commands do not undergo completion. | 1284 By default, the arguments of user defined commands do not undergo completion. |
1277 However, by specifying one or the other of the following attributes, argument | 1285 However, by specifying one or the other of the following attributes, argument |
1278 completion can be enabled: | 1286 completion can be enabled: |
1279 | 1287 |
1280 -complete=arglist file names in argument list | 1288 -complete=arglist file names in argument list |
1315 -complete=customlist,{func} custom completion, defined via {func} | 1323 -complete=customlist,{func} custom completion, defined via {func} |
1316 | 1324 |
1317 Note: That some completion methods might expand environment variables. | 1325 Note: That some completion methods might expand environment variables. |
1318 | 1326 |
1319 | 1327 |
1320 Custom completion *:command-completion-custom* | 1328 Custom completion ~ |
1321 *:command-completion-customlist* | 1329 *:command-completion-custom* |
1322 *E467* *E468* | 1330 *:command-completion-customlist* *E467* *E468* |
1323 It is possible to define customized completion schemes via the "custom,{func}" | 1331 It is possible to define customized completion schemes via the "custom,{func}" |
1324 or the "customlist,{func}" completion argument. The {func} part should be a | 1332 or the "customlist,{func}" completion argument. The {func} part should be a |
1325 function with the following signature: > | 1333 function with the following signature: > |
1326 | 1334 |
1327 :function {func}(ArgLead, CmdLine, CursorPos) | 1335 :function {func}(ArgLead, CmdLine, CursorPos) |
1362 :endfun | 1370 :endfun |
1363 < | 1371 < |
1364 This example does not work for file names with spaces! | 1372 This example does not work for file names with spaces! |
1365 | 1373 |
1366 | 1374 |
1367 Range handling *E177* *E178* *:command-range* | 1375 Range handling ~ |
1368 *:command-count* | 1376 *E177* *E178* *:command-range* *:command-count* |
1369 By default, user-defined commands do not accept a line number range. However, | 1377 By default, user-defined commands do not accept a line number range. However, |
1370 it is possible to specify that the command does take a range (the -range | 1378 it is possible to specify that the command does take a range (the -range |
1371 attribute), or that it takes an arbitrary count value, either in the line | 1379 attribute), or that it takes an arbitrary count value, either in the line |
1372 number position (-range=N, like the |:split| command) or as a "count" | 1380 number position (-range=N, like the |:split| command) or as a "count" |
1373 argument (-count=N, like the |:Next| command). The count will then be | 1381 argument (-count=N, like the |:Next| command). The count will then be |
1397 -addr=arguments Range for arguments | 1405 -addr=arguments Range for arguments |
1398 -addr=buffers Range for buffers (also not loaded buffers) | 1406 -addr=buffers Range for buffers (also not loaded buffers) |
1399 -addr=loaded_buffers Range for loaded buffers | 1407 -addr=loaded_buffers Range for loaded buffers |
1400 -addr=windows Range for windows | 1408 -addr=windows Range for windows |
1401 -addr=tabs Range for tab pages | 1409 -addr=tabs Range for tab pages |
1402 | 1410 -addr=other other kind of range |
1403 Special cases *:command-bang* *:command-bar* | 1411 |
1412 | |
1413 Special cases ~ | |
1414 *:command-bang* *:command-bar* | |
1404 *:command-register* *:command-buffer* | 1415 *:command-register* *:command-buffer* |
1405 There are some special cases as well: | 1416 There are some special cases as well: |
1406 | 1417 |
1407 -bang The command can take a ! modifier (like :q or :w) | 1418 -bang The command can take a ! modifier (like :q or :w) |
1408 -bar The command can be followed by a "|" and another command. | 1419 -bar The command can be followed by a "|" and another command. |
1416 is supplied, it is removed from the argument list and is available to the | 1427 is supplied, it is removed from the argument list and is available to the |
1417 replacement text separately. | 1428 replacement text separately. |
1418 Note that these arguments can be abbreviated, but that is a deprecated | 1429 Note that these arguments can be abbreviated, but that is a deprecated |
1419 feature. Use the full name for new scripts. | 1430 feature. Use the full name for new scripts. |
1420 | 1431 |
1421 Replacement text | 1432 |
1433 Replacement text ~ | |
1422 | 1434 |
1423 The replacement text for a user defined command is scanned for special escape | 1435 The replacement text for a user defined command is scanned for special escape |
1424 sequences, using <...> notation. Escape sequences are replaced with values | 1436 sequences, using <...> notation. Escape sequences are replaced with values |
1425 from the entered command line, and all other text is copied unchanged. The | 1437 from the entered command line, and all other text is copied unchanged. The |
1426 resulting string is executed as an Ex command. To avoid the replacement use | 1438 resulting string is executed as an Ex command. To avoid the replacement use |