Wikia

Vim Tips Wiki

Anwo

27 Edits since joining this wiki
November 4, 2007
Revision as of 12:57, July 13, 2012 by Anwo (Talk | contribs)

|
2
User talk:Anwo

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.

Around Wikia's network

Random Wiki