⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autocmd.txt

📁 MSYS在windows下模拟了一个类unix的终端
💻 TXT
📖 第 1 页 / 共 3 页
字号:
- Any file whose type is `&faf' or 'HTML', where the meaning of these types  depends on which version of Vim you are using.  Unknown types are considered NOT to match.You can also specify a type and a pattern at the same time (in which case theymust both match):> :au BufRead <&fff>diff*This will match files of type `&fff' whose names start with `diff'.Note that osfiletype checking is skipped if Vim is compiled without the|+osfiletype| feature.==============================================================================8. Groups						*autocmd-groups*Autocommands can be put together in a group.  This is useful for removing orexecuting a group of autocommands.  For example, all the autocommands forsyntax highlighting are put in the "highlight" group, to be able to execute":doautoall highlight BufRead" when the GUI starts.When no specific group is selected, Vim uses the default group.  The defaultgroup does not have a name.  You cannot execute the autocommands from thedefault group separately; you can execute them only by executing autocommandsfor all groups.Normally, when executing autocommands automatically, Vim uses the autocommandsfor all groups.  The group only matters when executing autocommands with":doautocmd" or ":doautoall", or when defining or deleting autocommands.The group name can contain any characters except white space.  The group name"end" is reserved (also in uppercase).  The group name is case sensitive.							*:aug* *:augroup*:aug[roup] {name}		Define the autocmd group name for the				following ":autocmd" commands.  The name "end"				or "END" selects the default group.To enter autocommands for a specific group, use this method:1. Select the group with ":augroup {name}".2. Delete any old autocommands with ":au!".3. Define the autocommands.4. Go back to the default group with "augroup END".Example:>	:augroup uncompress>	:  au!>	:  au BufEnter *.gz	%!gunzip>	:augroup ENDThis prevents having the autocommands defined twice (e.g., after sourcing the.vimrc file again).==============================================================================9. Executing autocommands				*autocmd-execute*Vim can also execute Autocommands non-automatically.  This is useful if youhave changed autocommands, or when Vim has executed the wrong autocommands(e.g., the file pattern match was wrong).Note that the 'eventignore' option applies here too.  Events listed in thisoption will not cause any commands to be executed.							*:do* *:doautocmd*:do[autocmd] [group] {event} [fname]			Apply the autocommands matching [fname] (default:			current file name) for {event} to the current buffer.			You can use this when the current file name does not			match the right pattern, after changing settings, or			to execute autocommands for a certain event.			It's possible to use this inside an autocommand too,			so you can base the autocommands for one extension on			another extension.  Example:>				:au Bufenter *.cpp so ~/.vimrc_cpp>				:au Bufenter *.cpp doau BufEnter x.c			Be careful to avoid endless loops.  See			|autocmd-nested|.			When the [group] argument is not given, Vim executes			the autocommands for all groups.  When the [group]			argument is included, Vim executes only the matching			autocommands for that group.  Note: if you use an			undefined group name, Vim gives you an error message.						*:doautoa* *:doautoall*:doautoa[ll] [group] {event} [fname]			Like ":doautocmd", but apply the autocommands to each			loaded buffer.  Careful: Don't use this for			autocommands that delete a buffer, change to another			buffer or change the contents of a buffer; the result			is unpredictable.  this command is intended for			autocommands that set options, change highlighting,			and things like that.==============================================================================10. Using autocommands					*autocmd-use*For WRITING FILES there are four possible pairs of events.  Vim uses only onepair at a time:BufWritePre	BufWritePost	writing the whole bufferFilterWritePre	FilterWritePost	writing to the temp file with filter inputFileAppendPre	FileAppendPost	appending to a fileFileWritePre	FileWritePost	any other file writeNote that the *WritePost commands should undo any changes to the buffer thatwere caused by the *WritePre commands; otherwise, writing the file will havethe side effect of changing the buffer.Before executing the autocommands, the buffer from which the lines are to bewritten temporarily becomes the current buffer.  Unless the autocommandschange the current buffer or delete the previously current buffer, thepreviously current buffer is made the current buffer again.The *WritePre and *AppendPre autocommands must not delete the buffer fromwhich the lines are to be written.The '[ and '] marks have a special position:- Before the *ReadPre event the '[ mark is set to the line just above where  the new lines will be inserted.- Before the *ReadPost event the '[ mark is set to the first line that was  just read, the '] mark to the last line.- Before executing the *WritePre and *AppendPre autocommands the '[ mark is  set to the first line that will be written, the '] mark to the last line.Careful: '[ and '] change when using commands that change the buffer.In commands which expect a file name, you can use "<afile>" for the file namethat is being read |:<afile>| (you can also use "%" for the current filename).  "<abuf>" can be used for the buffer number of the currently effectivebuffer.  This also works for buffers that doesn't have a name.  But it doesn'twork for files without a buffer (e.g., with ":r file").							*gzip-example*Examples for reading and writing compressed files:> :augroup gzip> :  autocmd!> :  autocmd BufReadPre,FileReadPre	*.gz set bin> :  autocmd BufReadPost,FileReadPost	*.gz '[,']!gunzip> :  autocmd BufReadPost,FileReadPost	*.gz set nobin> :  autocmd BufReadPost,FileReadPost	*.gz execute ":doautocmd BufReadPost " . expand("%:r")> :  autocmd BufWritePost,FileWritePost	*.gz !mv <afile> <afile>:r> :  autocmd BufWritePost,FileWritePost	*.gz !gzip <afile>:r>> :  autocmd FileAppendPre		*.gz !gunzip <afile>> :  autocmd FileAppendPre		*.gz !mv <afile>:r <afile>> :  autocmd FileAppendPost		*.gz !mv <afile> <afile>:r> :  autocmd FileAppendPost		*.gz !gzip <afile>:r> :augroup ENDThe "gzip" group is used to be able to delete any existing autocommands with":autocmd!", for when the file is sourced twice.("<afile>:r" is the file name without the extension, see |:_%:|)The commands executed for the BufNewFile, BufRead/BufReadPost, BufWritePost,FileAppendPost and VimLeave events do not set or reset the changed flag of thebuffer.  When you decompress the buffer with the BufReadPost autocommands, youcan still exit with ":q".  When you use ":undo" in BufWritePost to undo thechanges made by BufWritePre commands, you can still do ":q" (this also makes"ZZ" work).  If you do want the buffer to be marked as modified, set the'modified' option.To execute Normal mode commands from an autocommand, use the ":normal"command.  Use with care!  If the Normal mode command is not finished, the userneeds to type characters (e.g., after ":normal m" you need to type a markname).If you want the buffer to be unmodified after changing it, reset the'modified' option.  This makes it possible to exit the buffer with ":q"instead of ":q!".							*autocmd-nested*By default, autocommands do not nest.  If you use ":e" or ":w" in anautocommand, Vim does not execute the BufRead and BufWrite autocommands forthose commands.  If you do want this, use the "nested" flag for those commandsin which you want nesting.  For example:>	:autocmd FileChangedShell *.c nested e!The nesting is limited to 10 levels to get out of recursive loops.It's possible to use the ":au" command in an autocommand.  This can be aself-modifying command!  This can be useful for an autocommand that shouldexecute only once.There is currently no way to disable the autocommands.  If you want to write afile without executing the autocommands for that type of file, write it underanother name and rename it with a shell command.Note: When reading a file (with ":read file" or with a filter command) and thelast line in the file does not have an <EOL>, Vim remembers this.  At the nextwrite (with ":write file" or with a filter command), if the same line iswritten again as the last line in a file AND 'binary' is set, Vim does notsupply an <EOL>.  This makes a filter command on the just read lines write thesame file as was read, and makes a write command on just filtered lines writethe same file as was read from the filter.  For example, another way to writea compressed file:> :autocmd FileWritePre *.gz   set bin|'[,']!gzip> :autocmd FileWritePost *.gz  undo|set nobin							*autocommand-pattern*You can specify multiple patterns, separated by commas.  Here are someexamples:> :autocmd BufRead   *		set tw=79 nocin ic infercase fo=2croq> :autocmd BufRead   .letter	set tw=72 fo=2tcrq> :autocmd BufEnter  .letter	set dict=/usr/lib/dict/words> :autocmd BufLeave  .letter	set dict=> :autocmd BufRead,BufNewFile   *.c,*.h	set tw=0 cin noic> :autocmd BufEnter  *.c,*.h	abbr FOR for (i = 0; i < 3; ++i)<CR>{<CR>}<Esc>O> :autocmd BufLeave  *.c,*.h	unabbr FORFor makefiles (makefile, Makefile, imakefile, makefile.unix, etc.):> :autocmd BufEnter  ?akefile*	set include=^s\=include> :autocmd BufLeave  ?akefile*	set include&To always start editing C files at the first function:> :autocmd BufRead   *.c,*.h	1;/^{Without the "1;" above, the search would start from wherever the file wasentered, rather than from the start of the file.						*skeleton* *template*To read a skeleton (template) file when opening a new file:> autocmd BufNewFile  *.c	0r ~/vim/skeleton.c> autocmd BufNewFile  *.h	0r ~/vim/skeleton.h> autocmd BufNewFile  *.java	0r ~/vim/skeleton.javaTo insert the current date and time in a *.html file when writing it:> autocmd BufWritePre,FileWritePre *.html   ks|call LastMod()|'s> fun LastMod()>   if line("$") > 20>     let l = 20>   else>     let l = line("$")>   endif>   exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .>   \ strftime("%Y %b %d")> endfunYou need to have a line "Last modified: <date time>" in the first 20 linesof the file for this to work.  Vim replaces <date time> (and anything in thesame line after it) with the current date and time.  Explanation:	ks		mark current position with mark 's'	call LastMod()  call the LastMod() function to do the work	's		return the cursor to the old positionThe LastMod() function checks if the file is shorter than 20 lines, and thenuses the ":g" command to find lines that contain "Last modified: ".  For thoselines the ":s" command is executed to replace the existing date with thecurrent one.  The ":execute" command is used to be able to use an expressionfor the ":g" and ":s" commands.  The date is obtained with the strftime()function.  You can change its argument to get another date string.When entering :autocmd on the command-line, completion of events and commandnames may be done (with <Tab>, CTRL-D, etc.) where appropriate.Vim executes all matching autocommands in the order that you specify them.It is recommended that your first autocommand be used for all files by using"*" as the file pattern.  This means that you can define defaults you likehere for any settings, and if there is another matching autocommand it willoverride these.  But if there is no other matching autocommand, then at leastyour default settings are recovered (if entering this file from another forwhich autocommands did match).  Note that "*" will also match files startingwith ".", unlike Unix shells.						    *autocmd-searchpat*Autocommands do not change the current search patterns.  Vim saves the currentsearch patterns before executing autocommands then restores them after theautocommands finish.  This means that autocommands do not affect the stringshighlighted with the 'hlsearch' option.  Within autocommands, you can stilluse search patterns normally, e.g., with the "n" command.If you want an autocommand to set the search pattern, such that it is usedafter the autocommand finishes, use the ":let @/ =" command.The search-highlighting cannot be switched off with ":nohlsearch" in anautocommand.  Use the 'h' flag in the 'viminfo' option to disable search-highlighting when starting Vim. vim:tw=78:ts=8:sw=8:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -