From 72fe59ffaaedbcfcb74cc13c7fc85d2f359d639f Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 4 Apr 2019 16:53:46 +0100 Subject: [PATCH] Only invoke last change substitution in help files Previously the `autocmd` to replace the date on the first line if `Last change: ` was present resulted in the cursor being moved in non `help` filetypes due to the substitution failing. Now the substitution is only attempted if the current file is a `help` file. --- autoload/do.vim | 8 ++++++++ plugin/autocmds.vim | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/autoload/do.vim b/autoload/do.vim index aaaaedd..c0f39be 100644 --- a/autoload/do.vim +++ b/autoload/do.vim @@ -78,3 +78,11 @@ function! do#debug(...) endfor exec l:command endfunction + +function! do#last_change() + if &filetype ==# 'help' + " vint: next-line -ProhibitCommandRelyOnUser -ProhibitCommandWithUnintendedSideEffect + 1s/Last change: \zs.*$/\=strftime('%Y %b %d')/e + norm!`` + endif +endfunction diff --git a/plugin/autocmds.vim b/plugin/autocmds.vim index 552e119..8b16cfb 100644 --- a/plugin/autocmds.vim +++ b/plugin/autocmds.vim @@ -9,7 +9,7 @@ augroup benieAugroup au FileType * call matchadd('Todo', '^\(<<<<<<<\||||||||\|=======\|>>>>>>>\)\s\ze.*$') " Update `Last change: ` on write then jump back previous position - au BufWritePost *.txt 1s/Last change: \zs.*$/\=strftime('%Y %b %d')/e|norm!`` + au BufWritePost *.txt silent! call do#last_change() " Read template into buffer then send line 1 to the black hold register au BufNewFile todo.md read ~/.vim/templates/skeleton.todo.md | 1delete _