Skip to content

Commit 9b4309a

Browse files
authored
Merge pull request #1109 from tsuyoshicho/update/20220612/autocmd
Update autocmd.{txt,jax}
2 parents 3692640 + 18bf559 commit 9b4309a

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

doc/autocmd.jax

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*autocmd.txt* For Vim バージョン 9.0. Last change: 2022 Apr 17
1+
*autocmd.txt* For Vim バージョン 9.0. Last change: 2022 May 24
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -46,6 +46,28 @@
4646
る場合がたまにある)。可能であれば、イベント File* や Buf* には同じ自動コマン
4747
ドを使うのはよい考えだ。
4848

49+
推奨される使用法:
50+
- 常にグループを使用することで、自動コマンドの削除が容易になる。
51+
- コマンド自体を短く維持し、より多くの仕事をする関数を呼ぶようにする。
52+
- 定義されているスクリプトを、自動コマンドを繰り返さずに数回ソースできるように
53+
する。
54+
55+
Vim9 script での例: >
56+
autocmd_add({replace: true,
57+
group: 'DemoGroup',
58+
event: 'BufEnter',
59+
pattern: '*.txt',
60+
cmd: 'call DemoBufEnter()'
61+
})
62+
63+
旧来のスクリプトの例: >
64+
call autocmd_add(#{replace: v:true,
65+
\ group: 'DemoGroup',
66+
\ event: 'BufEnter',
67+
\ pattern: '*.txt',
68+
\ cmd: 'call DemoBufEnter()'
69+
\ })
70+
4971
==============================================================================
5072
2. 自動コマンドの定義 *autocmd-define*
5173

@@ -79,6 +101,10 @@
79101
/<start
80102
}
81103
104+
|autocmd_add()| 関数は、Vim script から自動コマンドやグループのリストを追加す
105+
るために使用できる。`:autocmd``:execute` を使用する必要があるような場合は、
106+
この関数を使用することが好ましい。
107+
82108
Note: ":autocmd" コマンドの後には、パターンが期待される位置に '|' が現れる場合
83109
にのみ別のコマンドを続けることができる。これは動作する: >
84110
:augroup mine | au! BufRead | augroup END
@@ -144,6 +170,9 @@ Note [group] はあらかじめ定義されていなければならないこと
144170
==============================================================================
145171
3. 自動コマンドの除去 *autocmd-remove*
146172

173+
以下で説明するコマンドに加えて、|autocmd_delete()| 関数を使用し Vim script か
174+
ら自動コマンドおよびグループのリストを削除できる。
175+
147176
:au[tocmd]! [group] {event} {aupat} [++once] [++nested] {cmd}
148177
{event}{aupat} に関連づけられた全ての自動コマンド
149178
を除去し、コマンド {cmd} を加える。
@@ -198,6 +227,8 @@ Note [group] はあらかじめ定義されていなければならないこと
198227
バッファローカルな自動コマンドを列挙するには、<buffer>または<buffer=N>という形
199228
のパターンを使う。|autocmd-buflocal|を参照。
200229

230+
|autocmd_get()| 関数で自動コマンドのリストを Vim script から取得できる。
231+
201232
*:autocmd-verbose*
202233
'verbose' がゼロでないならば、自動コマンドを列挙するときに、それが最後にどこで
203234
定義されたかも表示する。例: >

en/autocmd.txt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*autocmd.txt* For Vim version 9.0. Last change: 2022 Apr 17
1+
*autocmd.txt* For Vim version 9.0. Last change: 2022 May 24
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -47,6 +47,28 @@ effects. Be careful not to destroy your text.
4747
It's a good idea to use the same autocommands for the File* and Buf* events
4848
when possible.
4949

50+
Recommended use:
51+
- Always use a group, so that it's easy to delete the autocommand.
52+
- Keep the command itself short, call a function to do more work.
53+
- Make it so that the script it is defined in can be sourced several times
54+
without the autocommand being repeated.
55+
56+
Example in Vim9 script: >
57+
autocmd_add({replace: true,
58+
group: 'DemoGroup',
59+
event: 'BufEnter',
60+
pattern: '*.txt',
61+
cmd: 'call DemoBufEnter()'
62+
})
63+
64+
In legacy script: >
65+
call autocmd_add(#{replace: v:true,
66+
\ group: 'DemoGroup',
67+
\ event: 'BufEnter',
68+
\ pattern: '*.txt',
69+
\ cmd: 'call DemoBufEnter()'
70+
\ })
71+
5072
==============================================================================
5173
2. Defining autocommands *autocmd-define*
5274

@@ -82,6 +104,10 @@ triggered.
82104
/<start
83105
}
84106
107+
The |autocmd_add()| function can be used to add a list of autocmds and autocmd
108+
groups from a Vim script. It is preferred if you have anything that would
109+
require using `:execute` with `:autocmd`.
110+
85111
Note: The ":autocmd" command can only be followed by another command when the
86112
'|' appears where the pattern is expected. This works: >
87113
:augroup mine | au! BufRead | augroup END
@@ -146,6 +172,9 @@ prompt. When one command outputs two messages this can happen anyway.
146172
==============================================================================
147173
3. Removing autocommands *autocmd-remove*
148174

175+
In addition to the below described commands, the |autocmd_delete()| function can
176+
be used to remove a list of autocmds and autocmd groups from a Vim script.
177+
149178
:au[tocmd]! [group] {event} {aupat} [++once] [++nested] {cmd}
150179
Remove all autocommands associated with {event} and
151180
{aupat}, and add the command {cmd}.
@@ -198,6 +227,9 @@ argument behavior differs from that for defining and removing autocommands.
198227
In order to list buffer-local autocommands, use a pattern in the form <buffer>
199228
or <buffer=N>. See |autocmd-buflocal|.
200229

230+
The |autocmd_get()| function can be used from a Vim script to get a list of
231+
autocmds.
232+
201233
*:autocmd-verbose*
202234
When 'verbose' is non-zero, listing an autocommand will also display where it
203235
was last defined. Example: >

0 commit comments

Comments
 (0)