I'm trying to make Vim run the command 'CommandTFlush' whenever a new file is writte. For those not using the Command-T plugin, the 'CommandTFlush' command is used to rebuild an index of files in the current directory.
What I want to do is run the command after the file is written to disk, so that CommandTFlush will find the file and add it to it's index.
I've tried writing a function myself, but either it doesn't fire or it fires too soon (before the file is written, and the whole point is to add the file to the index):
au! BufWritePre * ks| call NewFilesUpdatesCommandT()
function! NewFilesUpdatesCommandT()
let filename=@%
if !filereadable(filename)
CommandTFlush
endif
endfunction
I suspect it could be solved by setting some boolean var (isTheFileNew) in BufWritePre and then execute the CommandTFlush command in BufWritePost if the file was just created, but I can't figure out the syntax. Another solution could be setting/unsetting the BufWritePost callback from within BufWritePre callback, if that's possible...
Could anybody help me out here? ;)
The FLUSH command halts processing of a file currently being transmitted on a link. The file is either purged or held, and link processing continues with the next file queued for transmission on the link.
Clearing the DNS server will remove any invalid addresses, whether because they're outdated or because they've been manipulated. It's also important to note flushing the cache doesn't have any negative side effects.
Here is my solution. It triggers CommandTFlush whenever a file is written and also whenever Vim's window gains focus. This is useful when you create files outside of vim - for example by switching between branches in your version control system. The new files will be available in CommandT immediately after you re-enter Vim.
augroup CommandTExtension
autocmd!
autocmd FocusGained * CommandTFlush
autocmd BufWritePost * CommandTFlush
augroup END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With