Skip to content

Commit 75ce2e1

Browse files
authored
Merge pull request #2687 from h-east/update-map
Update map.{txt,jax}
2 parents 29e53b2 + e89c66e commit 75ce2e1

2 files changed

Lines changed: 100 additions & 2 deletions

File tree

doc/map.jax

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*map.txt* For Vim バージョン 9.2. Last change: 2026 May 23
1+
*map.txt* For Vim バージョン 9.2. Last change: 2026 Jun 13
22

33

44
VIM リファレンスマニュアル by Bram Moolenaar
@@ -1604,6 +1604,11 @@ non-id マッチした場所の前がスペース、タブ、行頭、挿入
16041604
16051605
:MyCmd2 two values
16061606
1607+
引数エリア全体をそのまま単一の値として扱いたい場合は、-nargs=_ を使用する。複
1608+
数の引数が必要で、かつ個々の引数自体にスペースが含まれる可能性がある場合 (その
1609+
ため、分割処理を継続させる必要がある場合) は、代わりに -nargs=+/* を、
1610+
|:command-completeopt| (-completeopt=escape) と組み合わせて使用する。
1611+
16071612

16081613
Note: 引数は Vim script の式としてではなく、テキストとして解釈されることに注
16091614
意。具体的な例を上げると、"s:var" を引数として渡すと、そのコマンドを実行したス
@@ -1737,6 +1742,50 @@ Note: いくつかの補完方法は環境変数を展開します。
17371742
<
17381743
この例はファイル名にスペースが含まれていると機能しません!
17391744

1745+
*:command-completeopt*
1746+
"custom" および "customlist" タイプの場合、-completeopt= 属性を使用して特定の
1747+
動作をさらに選択できる。この属性は、オプション名をコンマで区切ったリストを受け
1748+
取る。現在認識されるのは "escape" のみである。
1749+
1750+
-completeopt=escape
1751+
補完関数は、スペース、タブ、バックスラッシュを含むマッチを返す
1752+
場合がある。このようなマッチがコマンドラインに挿入されると、各
1753+
スペース、タブ、バックスラッシュの前にバックスラッシュが付加さ
1754+
れ、値が単一の引数として保持される。表示にはエスケープされてい
1755+
ない形式が使用される (ポップアップメニュー / ワイルドメニュー
1756+
/ |getcompletion()|)。補完関数に渡される ArgLead もエスケープ
1757+
されていない。ユーザーが `:Cmd foo\ b<Tab>` と入力すると、関数
1758+
は `foo b` で呼び出され、`foo\ b` では呼び出されない。コマンド
1759+
の置換テキストでは、|<q-args>||<f-args>| も同様にエスケー
1760+
プされていない値を返す。
1761+
1762+
例: >
1763+
:func MyComplete(ArgLead, CmdLine, CursorPos)
1764+
: return filter(['hello world', 'good morning'],
1765+
: \ {_, v -> stridx(v, a:ArgLead) ==# 0})
1766+
:endfunc
1767+
:com! -nargs=1 -complete=customlist,MyComplete -completeopt=escape MyCmd
1768+
\ echo <q-args>
1769+
<
1770+
`:MyCmd <Tab>` の後、ポップアップには `hello world` と `good morning` が表示さ
1771+
れる。`:MyCmd hello\ w<Tab>` と入力すると、ArgLead が `hello w` (スペースの前
1772+
のバックスラッシュが削除される) に設定された状態で MyComplete が呼び出され、
1773+
フィルタが `hello world` を見つけ、`<Tab>` がそれを `:MyCmd hello\ world` とし
1774+
て挿入する。その後、`<q-args>` は論理値 `hello world` に評価される。
1775+
1776+
-completeopt=escape を指定しない場合、リテラル文字列 `hello world` がコマンド
1777+
ラインに挿入されるため、Vim の引数分割機能はそれを 2 つの引数として扱う。
1778+
1779+
-completeopt=escape と -nargs=_ (|:command-nargs| を参照) は異なる形態を対象と
1780+
しており、同じ形態に対する競合する解決策ではない:
1781+
"行全体を 1 つの引数として扱う。エスケープなし"
1782+
-nargs=_ を使用する
1783+
"複数の引数があり、それぞれにスペースを含めることができる"
1784+
-completeopt=escape と一緒に -nargs=+ または -nargs=*
1785+
を使用する
1786+
-nargs=_ は引数分割を無効にするため、エスケープは効果がない。したがって、
1787+
-nargs=_ と -completeopt=escape を組み合わせるとエラーになる (E1579)。
1788+
17401789

17411790
範囲指定 ~
17421791
*E177* *E178* *:command-range* *:command-count*

en/map.txt

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*map.txt* For Vim version 9.2. Last change: 2026 May 23
1+
*map.txt* For Vim version 9.2. Last change: 2026 Jun 13
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1620,6 +1620,11 @@ Completing ":MyCmd2 two va<tab>" will complete with: >
16201620
16211621
:MyCmd2 two values
16221622
1623+
Use -nargs=_ when the whole argument area should be taken as a single value
1624+
as-is. When you need several arguments and an individual argument may itself
1625+
contain spaces (so the splitter must keep running), use -nargs=+/* together
1626+
with |:command-completeopt| (-completeopt=escape) instead.
1627+
16231628

16241629
Note that arguments are used as text, not as expressions. Specifically,
16251630
"s:var" will use the script-local variable in the script where the command was
@@ -1758,6 +1763,50 @@ the 'path' option: >
17581763
<
17591764
This example does not work for file names with spaces!
17601765

1766+
*:command-completeopt*
1767+
For the "custom" and "customlist" types you can further opt into specific
1768+
behaviors with the -completeopt= attribute. It takes a comma-separated list
1769+
of option names; currently only "escape" is recognized:
1770+
1771+
-completeopt=escape
1772+
The completion function may return matches containing spaces,
1773+
tabs or backslashes. When such a match is inserted into the
1774+
command line each space, tab and backslash is preceded by a
1775+
backslash so the value is preserved as a single argument. The
1776+
unescaped form is used for display (popup menu / wildmenu /
1777+
|getcompletion()|). The ArgLead passed to the completion
1778+
function is also unescaped: when the user types
1779+
`:Cmd foo\ b<Tab>` the function is called with `foo b`, not
1780+
`foo\ b` . In the command's replacement text |<q-args>| and
1781+
|<f-args>| likewise yield the unescaped value.
1782+
1783+
Example: >
1784+
:func MyComplete(ArgLead, CmdLine, CursorPos)
1785+
: return filter(['hello world', 'good morning'],
1786+
: \ {_, v -> stridx(v, a:ArgLead) ==# 0})
1787+
:endfunc
1788+
:com! -nargs=1 -complete=customlist,MyComplete -completeopt=escape MyCmd
1789+
\ echo <q-args>
1790+
<
1791+
After `:MyCmd <Tab>` the popup shows `hello world` and `good morning`. Typing
1792+
`:MyCmd hello\ w<Tab>` calls MyComplete with ArgLead set to `hello w` (the
1793+
backslash before the space is removed), the filter finds `hello world`, and
1794+
`<Tab>` inserts it as `:MyCmd hello\ world`. `<q-args>` then evaluates to the
1795+
logical `hello world`.
1796+
1797+
Without -completeopt=escape the literal string `hello world` would be inserted
1798+
into the command line, so Vim's argument splitter would treat it as two
1799+
arguments.
1800+
1801+
-completeopt=escape and -nargs=_ (see |:command-nargs|) target different
1802+
shapes; they are not competing solutions for the same one:
1803+
"whole line as one argument, no escaping"
1804+
use -nargs=_
1805+
"multiple arguments, each may contain spaces"
1806+
use -nargs=+ or -nargs=* with -completeopt=escape
1807+
Because -nargs=_ disables the argument splitter, escaping has no effect there,
1808+
so combining -nargs=_ with -completeopt=escape is an error (E1579).
1809+
17611810

17621811
Range handling ~
17631812
*E177* *E178* *:command-range* *:command-count*

0 commit comments

Comments
 (0)