From 38a483f2781b091bccc320f2c51370ed361632c7 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Thu, 16 Apr 2015 23:21:37 +0800 Subject: [PATCH] Update --- vimscript.md | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/vimscript.md b/vimscript.md index f2c76e00d..b85d903bd 100644 --- a/vimscript.md +++ b/vimscript.md @@ -110,14 +110,38 @@ function! infect(...) endfunction ``` -Commands --------- +Custom commands +--------------- + +Custom commands start with uppercase letters. The `!` redefines a command if it already exists. ```vim -command! Save set fo=want tw=80 nowrap -command! Save call s:Foo() +command! Save :set fo=want tw=80 nowrap ``` +### Commands calling functions + +```vim +command! Save call script#foo() +function! script#foo() + ... +endfunction +``` + +### Commands with arguments + +```vim +command! -nargs=? Save call script#foo( +``` + +| What | What | +| ---- | ---- | +| `-nargs=0` | 0 arguments, default | +| `-nargs=1` | 1 argument, includes spaces | +| `-nargs=?` | 0 or 1 argument | +| `-nargs=*` | 0+ arguments, space separated | +| `-nargs=+` | 1+ arguments, space reparated | + Flow ----