I have a simple BufWritePost autocmd to automatically generate HTML from my vimwiki pages.
autocmd BufWritePost *.wiki VimwikiAll2HTML
But it spits out a lot of progress output, and a prompt at the end:
Press ENTER or type command to continue
Is there a way to suppress the output and prompt from a vim autocmd, to make it completely transparent?
Try to add silent after the pattern.
autocmd BufWritePost *.wiki silent VimwikiAll2HTML
And add your autocmd that works well to your question, it will greatly help.
You can try another option:
:h vimwiki-option-auto_export
Related
I want use the indent linux utility to indent the current file on saving. I tried
autocmd BufWritePre *.[ch] :!indent -kr -nut %
in my .vimrc file (~/.vim).
Manually I tried that command
:!indent -kr -nut %
it works only after prompting me to load the file, as below,
See ":help W12" for more info.
[O]K, (L)oad File:
You don't want BufWritePre because that modifies your file before saving it. Instead, try doing BufWritePost:
autocmd BufWritePost *.[ch] !indent -kr -nut %
This will still ask you to hit enter, but it doesn't prompt to load the file when I test it. If you don't want to have to hit enter after saving, you can change this to:
autocmd BufWritePost *.[ch] exec "!indent -kr -nut %" | redraw
Also, note how I removed the : from your command. This is because autocmd looks for an ex command, so the : is unneeded.
How can I change a current working directory for a specific buffer and change it to a previous value for other buffers?
More precisely what I want to do is to have auto-commands for specific file types which will change a current working directory when a buffer containing the file type is active. And change it back when working with other buffers.
I had something like that in my vimrc:
autocmd BufEnter *.py :lcd%:p:h
autocmd BufLeave *.py :lcd-
The idea here is that I wanted to switch to file's directory when working on python files and switch to a previous directory when working on something else, e.g. text, vimL etc. Obviously, it didn't work. I also try using BufWinLeave, but it didn't change anything.
Can you point out what's wrong here? Or maybe there's an easier solution for that?
I think you could accomplish something similar with the following:
augroup CDRooter
autocmd!
autocmd BufWinEnter * if &filetype == 'python' | lcd %:p:h | else | lcd! | endif
augroup END
Note: I am not sure :lcd - will work well. Instead I use :lcd! to simply revert the window to using the global current working directory.
The basic idea is whenever you enter a window sniff the filetype and execute :lcd accordingly.
For more help see:
:h 'filetype'
:h BufWinEnter
:h :lcd
:h :augroup
:h :autocmd
:h :if
YouCopmleteMe is pretty awesome, however there is one behaviour I would like to change, and thats the ability to force compilation and diagnostics to be executed when you save the file. Currently one can put the following in their vimrc to press F5 to force compile:
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
You need to trigger that command on the event of saving using an autocmd:
autocmd BufWritePost * YcmForceCompileAndDiagnostics
Or mabye just for certain file extensions:
autocmd BufWritePost *.c YcmForceCompileAndDiagnostics
See :help autocommand and :help BufWritePost.
HTH
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 autocommand to:
autocmd FocusLost * nested silent! wall
See :h autocmd-nested for details.
I can't test this in a graphic Vim, but you can try some options:
Join some events in the same autocommand autocmd BufWritePre,FocusLost *.py ...
Execute an autocommand from an event, something like:
autocmd BufWritePre *.py :execute "%s/\s\+$//e" | doautocmd FocusLost %
I have installed Markdown syntax plugin.
When I'm on a new buffer not associated with any file, and paste the source portion of the site http://rosylilly.github.com/markdown.html into it, the colors appear nicely as it should for the markdown syntax.
However, after saving the file, the colors change. Any idea how I can fix this?
Can you, before and after saving do
:verbose set filetype
:verbose set
Tip: use :redir > file.txt to capture the output so you won't have to copy/paste which can be difficult with gvim - for command output
You could also look at the autocommands when saving:
:verbose au BufWrite
:verbose au BufWritePre
:verbose au BufWritePost
This would serve to discover what plugin/script is causing the highlighting to go haywire.