From ce8ddf37fc28dc705559edadb1c783c565fac0b6 Mon Sep 17 00:00:00 2001 From: Brennen Bearnes Date: Sun, 10 Feb 2019 20:02:27 -0700 Subject: [PATCH] Fix autocmds & alternate file handling for "index" This commit tweaks the existing autocommand for files matching `index{,.lock}` to: - Fire BufReadPre and BufReadPost on either side of the read operation for files not in a `.git/` and already extant. - Fire BufNewFile for new files not in a `.git`. - Add `keepalt` to the `read`, thus allowing alternative file operations such as Ctrl-^ to work correctly. Has been tested against: - BufReadPost,BufNewFile autocommands - A basic test case for alternate files where one is named `index` Closes https://github.com/tpope/vim-fugitive/issues/834 Closes https://github.com/tpope/vim-fugitive/issues/959 --- plugin/fugitive.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index ca67b57..c5f7046 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -271,14 +271,21 @@ augroup fugitive \ endif | \ let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') . '|setl inex= inc=' + " Handle index files in Git directories, emulating normal sequence of + " autocommands if a file named `index` is found elsewhere: autocmd BufReadCmd index{,.lock} \ if FugitiveIsGitDir(expand(':p:h')) | \ let b:git_dir = s:Slash(expand(':p:h')) | \ exe fugitive#BufReadStatus() | \ elseif filereadable(expand('')) | - \ read | + \ silent doautocmd BufReadPre | + \ keepalt read | \ 1delete_ | + \ silent doautocmd BufReadPost | + \ else | + \ silent doautocmd BufNewFile | \ endif + autocmd BufReadCmd fugitive://*//* exe fugitive#BufReadCmd() autocmd BufWriteCmd fugitive://*//[0-3]/* exe fugitive#BufWriteCmd() autocmd FileReadCmd fugitive://*//* exe fugitive#FileReadCmd()