78 lines · 3.0 KB · Text
RawDownload
Tests for autocommands:- FileWritePre		writing a compressed file- FileReadPost		reading a compressed file- BufNewFile		reading a file template- BufReadPre		decompressing the file to be read- FilterReadPre		substituting characters in the temp file- FilterReadPost	substituting characters after filtering- FileReadPre		set options for decompression- FileReadPost		decompress the file Note: This test will fail if "gzip" is not available.$GZIP is made empty, "-v" would cause trouble.Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" beingmodified outside of Vim (noticed on Solaris). STARTTEST:so small.vim:let $GZIP = "":au FileChangedShell * echo "caught FileChangedShell":set bin:au FileWritePre    *.gz   '[,']!gzip:au FileWritePost   *.gz   undo:/^start of testfile/,/^end of testfile/w! Xtestfile.gz:au FileReadPost    *.gz   '[,']!gzip -d:$r Xtestfile.gz                " Read and decompress the testfile:?startstart?,$w! test.out      " Write contents of this file:au BufNewFile      *.c    read Xtest.c:/^start of test.c/+1,/^end of test.c/-1w! Xtest.c:e! foo.c                       " Will load Xtest.c:au FileAppendPre   *.out  '[,']s/new/NEW/:au FileAppendPost  *.out  !cat Xtest.c >>test.out:w>>test.out                    " Append it to the output file:au! FileAppendPre:" setup autocommands to decompress before reading and re-compress afterwards:au BufReadPre      *.gz   !gzip -d <afile>:au BufReadPre      *.gz   call rename(expand("<afile>:r"), expand("<afile>")):au BufReadPost     *.gz   call rename(expand("<afile>"), expand("<afile>:r")):au BufReadPost     *.gz   !gzip <afile>:r:e! Xtestfile.gz                " Edit compressed file:w>>test.out                    " Append it to the output file:set shelltemp                  " need temp files here:au FilterReadPre   *.out  call rename(expand("<afile>"), expand("<afile>").".t"):au FilterReadPre   *.out  !sed s/e/E/ <afile>.t ><afile>:au FilterReadPre   *.out  !rm <afile>.t:au FilterReadPost  *.out  '[,']s/x/X/g:e! test.out                    " Edit the output file:23,$!cat:23,$s/\r$//                 " remove CR for when sed adds them:au! FileReadPre    *.gz   !gzip -d <afile>:au  FileReadPre    *.gz   call rename(expand("<afile>:r"), expand("<afile>")):au! FileReadPost   *.gz   '[,']s/l/L/:$r Xtestfile.gz             " Read compressed file:w                           " write it, after filtering:au!             " remove all autocommands:e               " Edit test.out again:set nobin ff&   " use the default fileformat for writing:w:qa!ENDTEST startstartstart of testfileline 2	Abcdefghijklmnopqrstuvwxyzline 3	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxline 4	Abcdefghijklmnopqrstuvwxyzline 5	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxline 6	Abcdefghijklmnopqrstuvwxyzline 7	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxline 8	Abcdefghijklmnopqrstuvwxyzline 9	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxline 10 Abcdefghijklmnopqrstuvwxyzend of testfile start of test.c/* * Here is a new .c file */end of test.c