Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | Test for BufWritePre autocommand that deletes or unloads the buffer. |
Bram Moolenaar | 2b90ed2 | 2013-07-24 16:02:36 +0200 | [diff] [blame] | 2 | Test for BufUnload autocommand that unloads all other buffers. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3 | |
| 4 | STARTTEST |
| 5 | :so small.vim |
| 6 | :au BufWritePre Xxx1 bunload |
| 7 | :au BufWritePre Xxx2 bwipe |
| 8 | /^start of |
| 9 | A1:.,/end of/w! Xxx1 " write test file Xxx1 |
| 10 | $r2:.,/end of/w! Xxx2 " write test file Xxx2 |
| 11 | :e! Xxx2 " edit Xxx2 |
| 12 | :bdel test8.in " delete this file from the buffer list |
| 13 | :e Xxx1 " edit Xxx1 |
| 14 | :w " write it, will unload it and give an error msg |
| 15 | :w! test.out " Write contents of this file |
| 16 | :e! Xxx2 " start editing Xxx2 |
| 17 | :bwipe test.out " remove test.out from the buffer list |
| 18 | :w " write it, will delete the buffer and give an error msg |
| 19 | :w >>test.out " Append contents of this file |
Bram Moolenaar | 2b90ed2 | 2013-07-24 16:02:36 +0200 | [diff] [blame] | 20 | :au! BufWritePre |
| 21 | :func CloseAll() |
| 22 | let i = 0 |
| 23 | while i <= bufnr('$') |
| 24 | if i != bufnr('%') && bufloaded(i) |
| 25 | exe i . "bunload" |
| 26 | endif |
| 27 | let i += 1 |
| 28 | endwhile |
| 29 | endfunc |
| 30 | :func WriteToOut() |
| 31 | edit! test.out |
| 32 | $put ='VimLeave done' |
| 33 | write |
| 34 | endfunc |
| 35 | :set viminfo='100,nviminfo |
| 36 | :au BufUnload * call CloseAll() |
| 37 | :au VimLeave * call WriteToOut() |
| 38 | :e small.vim |
| 39 | :sp mbyte.vim |
| 40 | :q |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 41 | :qa! |
| 42 | ENDTEST |
| 43 | |
| 44 | start of Xxx |
| 45 | test |
| 46 | end of Xxx |