|
|
| Line 2: |
Line 2: |
| |
---- |
|
---- |
| |
still intentionally left blank --[[User:Anwo|Anwo]] 10:18, March 31, 2011 (UTC) |
|
still intentionally left blank --[[User:Anwo|Anwo]] 10:18, March 31, 2011 (UTC) |
| |
+ |
|
| |
+ |
<small>There is so much material on this wiki ... before adding another redundant tip, I could as well fill my profile page first.</small> |
| |
+ |
|
| |
+ |
|
| |
+ |
== Autocommands accumulate == |
| |
+ |
When the line below is executed several times, this many BufDelete autocmds |
| |
+ |
will be installed: |
| |
+ |
<pre>:au BufDelete * let g:last_deleted_buf = expand("<abuf>")</pre> |
| |
+ |
|
| |
+ |
You can check the situation with |
| |
+ |
<pre>:au BufDelete *</pre> |
| |
+ |
or |
| |
+ |
<pre>:au BufDelete</pre> |
| |
+ |
|
| |
+ |
To REPLACE a previous definition, one normally adds a bang: |
| |
+ |
<pre>:au! BufDelete * let g:last_deleted_buf = expand("<abuf>")</pre> |
| |
+ |
|
| |
+ |
Problem here is that ALL existing `BufDelete *' autocmds are replaced by our |
| |
+ |
new one. |
| |
+ |
|
| |
+ |
Solution is to wrap the autocmd in an augroup: |
| |
+ |
<pre> |
| |
+ |
augroup MyBufferChecks |
| |
+ |
au! BufDelete * let g:last_deleted_buf = expand("<abuf>") |
| |
+ |
augroup End |
| |
+ |
</pre> |
| |
+ |
|
| |
+ |
or, alternatively: |
| |
+ |
<pre> |
| |
+ |
augroup MyBufferChecks |
| |
+ |
augroup End |
| |
+ |
au! MyBufferChecks BufDelete * let g:last_deleted_buf = expand("<abuf>") |
| |
+ |
</pre> |
| |
+ |
|
| |
+ |
By providing an :augroup, all :autocmd actions are local to that group. |
still intentionally left blank Anwo 11:46, October 15, 2009 (UTC)
still intentionally left blank --Anwo 10:18, March 31, 2011 (UTC)
There is so much material on this wiki ... before adding another redundant tip, I could as well fill my profile page first.
Autocommands accumulate
When the line below is executed several times, this many BufDelete autocmds
will be installed:
:au BufDelete * let g:last_deleted_buf = expand("<abuf>")
You can check the situation with
:au BufDelete *
or
:au BufDelete
To REPLACE a previous definition, one normally adds a bang:
:au! BufDelete * let g:last_deleted_buf = expand("<abuf>")
Problem here is that ALL existing `BufDelete *' autocmds are replaced by our
new one.
Solution is to wrap the autocmd in an augroup:
augroup MyBufferChecks
au! BufDelete * let g:last_deleted_buf = expand("<abuf>")
augroup End
or, alternatively:
augroup MyBufferChecks
augroup End
au! MyBufferChecks BufDelete * let g:last_deleted_buf = expand("<abuf>")
By providing an :augroup, all :autocmd actions are local to that group.