I'm using the Vim plugin clang_complete and I want to update the compilation errors in the QuickFix window whenever I save the file. So as the doc says, I must call the function g:ClangUpdateQuickFix().
The thing is that the next autocmd gives me the next message whenever it is executed despite it seems to work:
No matching autocommands
The autocmd I use is:
autocmd BufWritePost *.c,*.cpp,*.cxx,*.cc call g:ClangUpdateQuickFix()
What is the meaning of that message?
The displayed message come from clang_complete itself. Some vim plugins (not clang_complete) are reparsing the quickfix window whenever it changes. Fortunately, vim provide an autocmd for that: QuickFixCmdPost, so these plugins are using this to reparse the quickfix messages.
In clang_complete, since we're modifiying the quickfix window and we don't want to break existing plugins, we need to trigger this autocmd manually. What you get is the No matching autocommands message when you don't use those plugins.
Related
I've recently installed the VimWiki plug-in, and am learning about Vim's plugin architecture in general (and better using directories like after/ftplugin instead of cramming everything into my .vimrc file).
I would like to call a function prior to writing wiki files, like so:
autocmd BufWrite *.wiki call CleanMarkdown()
However, vimwiki sets its own BufWrite autocommand, which updates any tables-of-contents in the wiki file. I could clobber this autocommand with my own function that calls both the CleanMarkdown() plus whatever vimwiki is doing today, but that would be brittle in the face of possible future changes in the vimwiki plugin.
Is there a standard way to add to the list of things to do for a BufWrite autocommand?
Multiplicity of autocmds
There can be many :autocmds for any event; the command is cummulative. The corresponding :autocmd! removes certain sets of commands (depending on the arguments given to it).
If you don't specify a [group], the autocmd will be defined in the global space, and there's a high risk of getting this cleared by some :autocmd!. Therefore, it is recommended to specify a [group] (especially in plugins). With this, you avoid that another (mis-behaving) plugin or customization clobbers your autocmd.
Integrating with vimwiki plugin
As the plugin already defines its own filetype, you don't need to duplicate the filetype detection logic, i.e. the *.wiki pattern. Instead, if you put your :autocmd definition in ~/.vim/after/ftplugin/vimwiki.vim, you can use the <buffer> special pattern to make this autocmd apply only to the current (VimWiki) buffer.
augroup MyVimWikiCleanup
autocmd BufWrite <buffer> call CleanMarkdown()
augroup END
Ordering
The :autocmds are executed in the order in which they were defined. By using the after directory, yours will be executed after the plugin's.
I'm happily loading either Notes and Txtfmt plugins in neovim, command line version, on Mac Os Sierra.
Both greatly working on their own, but no chance to have 'em loading together in a file of filetype notes.txtfmt as per Vim documentation about dot-separated filetypes.
First attempt I made was following Notes documentation to be able to work together with Txtfmt and creating the file
$/.vim/after/ftplugin/notes.vim
with the content:
" Enable Txtfmt formatting inside notes.
setlocal filetype=notes.txtfmt
As stated in this discussion this approach does not work, creating an infinite loop.
Next, as suggested by bpstahlman in the mentioned post, I added to my .vimrc the following autocommand:
augroup TxtfmtInNotes
au!
au FileType * if expand("<amatch>") == "notes" | setlocalft=notes.txtfmt|endif
augroup END
Now, it seemed that could be working, in that it declares a 'notes.txtfmt' filetype in Vim status bar, immediately after opening a new :Note buffer.
The bad news: txtfmt plugin does not load, no mapped command is working.
The funny: doing again :setlocal ft=notes.txtfmt
(which is supposed to have already been done by the suggested autocommand) everything gets properly loaded.
In other words it looks like in my case the autocommand works in changing filetype but not in loading the txtfmt plugin, which is loaded only repeating the filetype command.
Any suggestion on this?
Thanks
If the Notes plugin had a filetype detection (apparently it hasn't, and the filetype is only set by the commands the plugin provides), I would overwrite that to
:au BufNewFile,BufRead *.note setf notes.txtfmt
In your case, instead of using a compound filetype, I would simply emulate its effects in ~/.vim/after/ftplugin/notes.vim:
runtime! ftplugin/txtfmt.vim ftplugin/txtfmt_*.vim ftplugin/txtfmt/*.vim
I haven't tested it, but it's more straightforward and therefore hopefully more robust than your current solution of hooking into the FileType event.
I use MacVim and in my .vimrc file I have map ,V :source $MYVIMRC<CR> binding that allows me to apply the newest version of .vimrc in a case it was recently modified.
However I noticed that strange things can happen, relaunch can slow down vim and some plugins can start to conflict after pressing ,V, when everything works fine if I just close and relaunch MacVim from the scratch.
I'd be very thankful if you could give me a hint on the reason of this behavior as I'd like to have a possibility to update .vimrc file that will completely clear internal vim state and grab new configuration file
The only viable way to re-apply your config to a pristine Vim is actually to restart it.
But the most likely cause of slow downs is the overuse/misuse of autocommands.
Autocommands are added without checking for existing ones. One consequence is that they tend to pile-up if you don't manage them properly and every individual autocommand corresponding to a specific event is executed when that event is triggered, leading to dreadful slow downs.
Here are the two ways you are supposed to use autocommands in your vimrc:
Method #1
" anywhere
augroup nameofthegroup
autocmd!
autocmd EventName pattern commandtoexecute
autocmd AnotherEventName anotherpattern anothercommandtoexecute
augroup END
Method #2
" near the top of your vimrc
augroup nameofthegroup
autocmd!
augroup END
" anywhere
autocmd nameofthegroup EventName pattern commandtoexecute
autocmd nameofthegroup AnotherEventName anotherpattern anothercommandtoexecute
The idea is to create a group of autocommands that clears itself whenever it is invoked and thus prevents them from piling-up.
For some reason the inclusion guard for quickfix filetype plugin doesn't works when its contents changes.
Inserting the following contents on ~/.vim/ftplugin/qf.vim
if exists("b:did_ftplugin")
finish
endif
call input("qf.vim!")
the message from the input() can be seem after issuing :copen.
But despite the include guard was set from the default filetype plugin on $VIMRUMTIME, as shown by :echo b:did_ftplugin and :1verbose setlocal stl, issuing :copen, :cold, :cnew or :helpg helpg also causes the message to be displayed.
This happens without additional plugins and no settings other than filetype plugin indent on
and set nocompatible.
My first guess was that any command refreshing the quickfix window closes the existing buffer and opens a new one. But including the let b:did_ftplugin = 1 after the endif above avoids the filetype plugin reload, as no message is displayed after the first :copen (but the default filetype plugin is completely skipped, as 'stl' isn't set anymore).
What could be the difference on between the b:did_ftplugin set on default filetype plugin and the one set from my home dir?
The quickfix window is mainly a view (window), though (for implementation reasons) it is backed by a Vim buffer. When I :cclose a quickfix window, and then :copen it again, the :ls! command shows an incremented buffer number. I think that explains the behavior you're seeing.
I'd like to have the tagbar VIM plugin launch when I open certain filetypes, so I added the following to my .vimrc:
if has("gui_running")
autocmd BufEnter *.hs nested TagbarOpen
However, this isn't working as I expected. It opens a side window, but the side window displays nothing and my cursor is trapped within it. I cannot switch windows with a click or with the CTRL-W movement commands.
However, when I run TagbarOpen manually, it works just fine.
Anyone else tried this, or is the above the wrong command to issue?
Interesting, that's a side effect of a convenience functionality that I hadn't anticipated. What happens is this: If TagbarOpen is called while the window is already open, Tagbar makes the cursor jump to its window instead of just doing nothing (for convenience like I said). So every time you try to leave the window by switching to the Haskell window, the autocommand causes it to jump right back. I've pushed a change that removes this functionality -- it probably wasn't that useful to begin with. So if you give the development version on GitHub a try (https://github.com/majutsushi/tagbar), it should work.
That the window is empty has a different reason: Haskell is not supported by Exuberant Ctags by default. But someone wrote a nice alternative for Haskell that works with Tagbar here: https://github.com/bitc/lushtags.
I actually have this exact configuration set up my vimrc for php files. Tagbar opens with function / variables loaded, cursor stays in php source file when Vim loads:
autocmd FileType php call SetPHPOptions()
function! SetPHPOptions()
setlocal shiftwidth=4 tabstop=4 softtabstop=4 expandtab makeprg=php-xdebug\ %
:call tagbar#autoopen(0)
endfunction
substitute 'php' for 'hs' or any other file type you want. List of filetypes at:
$VIMRUNTIME/filetype.vim
Have it running on MacVim (snapshot 72, Vim 7.4), and latest build of tagbar from https://github.com/majutsushi/tagbar