autocmd

Vim: disable autocmd BufRead (modeline)

梦想的初衷 提交于 2020-12-13 03:34:03
问题 From this answer I executed: :set modeline | doautocmd BufRead Since then, I cannot disable the BufRead . I can open a file and unset the modeline : :set nomodeline :e! :wq But when I reopen the same file, its modeline is again auto executed. I tried noautocmd - autocmd-remove: :noautocmd w BufRead :noautocmd BufRead :exe "au! BufRead *" :au! BufRead Note I want to disable all auto executed because of BufRead , not just a single event set by it like here explained: https://stackoverflow.com/a

Vim: Combining autocmd?

孤街浪徒 提交于 2020-01-01 05:21:07
问题 I need to do the logical-and of two autocmd events in vim. Basically, the command has to run on an InsertLeave when the FileType is tex. It seems like this should work (in a .vimrc): autocmd FileType tex :autocmd InsertLeave :w But it doesn't. The nested option doesn't seem to help either, even though the manual indicates it should. Its easy to do a logical-OR: autocmd BufEnter,BufLeave ... it mustn't be too hard to do a logical-AND. 回答1: I have a correction to @Eevee answer: to make

Call a function in Vim’s `autocmd` command

故事扮演 提交于 2019-12-23 13:08:52
问题 I want to use the expand function in an autocmd . In particular, I am adapting a tip by Paul Biggar and I wanted to use the following auto command in my .gvimrc : autocmd FileType tex set makeprg=rubber-info\ expand("%:t:r").log – Which of course doesn’t work. So what I actually want this to mean is that upon opening a tex file, the makeprg variable is set to the value of rubber-info filename.log where filename is the name of the TeX file without its file extension. How can I accomplish this?

Disable syntax highlighting for certain filenames

强颜欢笑 提交于 2019-12-11 02:55:15
问题 I have syntax highlighting enabled in .vimrc, but that makes loading certain files too long. So I need to disable (or, to be precise, not enable... enabling it and then disabling is not a solution) syntax highlighting for these files. I tried au BufNewFile,BufRead !*.inc syntax enable but that made just no syntax highlighting applied ever. The solution presented here does not work for me, since I can't make a distinction by filetype. I tried adapting to no avail, which might or might not be

Vim: Saving on FocusLost and executing auto command

谁说我不能喝 提交于 2019-12-07 23:59:52
问题 I've setup my vim editor (I use MacVim) to save files automatically when the focus is lost: autocmd FocusLost * silent! wall I also automatically strip trailing whitespace from python files using this auto command: autocmd BufWritePre *.py :%s/\s\+$//e This auto command works perfectly when I save the file manually (either by typing :w or by pressing ⌘s ) but it is not executed (i.e. the whitespace is not stripped) when I switch to another application and the buffer is automatically written.

Vim: Saving on FocusLost and executing auto command

余生颓废 提交于 2019-12-06 05:00:04
I've setup my vim editor (I use MacVim) to save files automatically when the focus is lost: autocmd FocusLost * silent! wall I also automatically strip trailing whitespace from python files using this auto command: autocmd BufWritePre *.py :%s/\s\+$//e This auto command works perfectly when I save the file manually (either by typing :w or by pressing ⌘s ) but it is not executed (i.e. the whitespace is not stripped) when I switch to another application and the buffer is automatically written. How can I modify these auto commands to make them work together? You need to change your FocusLost

Vim Buffer has been modified [duplicate]

有些话、适合烂在心里 提交于 2019-12-05 17:36:27
I am trying to implement an AutoCmd in Vim that needs to be executed when the current buffer has been modified. I have read through all the events available for AutoCmd in the docs but could not find something that would help determine when a buffer was modified or not. This doesn't necessarily mean "when a buffer was written" because the action I need to trigger needs to be called when the buffer has been modified including being written. Any ideas on how to implement a BufIsModified that could achieve this objective? Note: not a duplicate of What is a vimrc function to determine if a buffer

Vim: Combining autocmd?

左心房为你撑大大i 提交于 2019-12-03 16:09:42
I need to do the logical-and of two autocmd events in vim. Basically, the command has to run on an InsertLeave when the FileType is tex. It seems like this should work (in a .vimrc): autocmd FileType tex :autocmd InsertLeave :w But it doesn't. The nested option doesn't seem to help either, even though the manual indicates it should. Its easy to do a logical-OR: autocmd BufEnter,BufLeave ... it mustn't be too hard to do a logical-AND. I have a correction to @Eevee answer: to make autocommand work for one buffer only, you should use augroup TexAutoWrite autocmd FileType tex :autocmd!

Prevent saving files with certain names in Vim

半腔热情 提交于 2019-11-30 14:40:22
问题 I type really fast and realize that sometimes I accidentally save a file with the name of ; or : (I type :wq and sometimes a typo is introduced). Is there any way to write a macro that rejects saving files matching certain names? 回答1: A simple yet effective solution would be to define an auto-command matching potentially mistyped file names, that issues a warning and terminates saving. :autocmd BufWritePre [:;]* throw 'Forbidden file name: ' . expand('<afile>') Note that the :throw command is

Prevent saving files with certain names in Vim

本小妞迷上赌 提交于 2019-11-30 11:20:19
I type really fast and realize that sometimes I accidentally save a file with the name of ; or : (I type :wq and sometimes a typo is introduced). Is there any way to write a macro that rejects saving files matching certain names? A simple yet effective solution would be to define an auto-command matching potentially mistyped file names, that issues a warning and terminates saving. :autocmd BufWritePre [:;]* throw 'Forbidden file name: ' . expand('<afile>') Note that the :throw command is necessary to make Vim stop writing the contents of a buffer. In order to avoid getting E605 error because