From 9dd86353a61b41cf6a1de3c3741e8af8ac232c11 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 19 Apr 2013 21:59:42 +0200 Subject: [PATCH] vimrc: Search "do not edit" header in the first 20 lines only. --- vimrc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/vimrc b/vimrc index 39cadf0..82e8d33 100644 --- a/vimrc +++ b/vimrc @@ -981,13 +981,17 @@ if has('autocmd') endif " Display a warning when editing a file which contains "do not edit" (ignoring -" the case, \c), for example template files which were preprocessed or -" auto-generated files. Especially useful when the header is not displayed on -" the first screen, e.g. when the old position is restored. Not for vimrc -" though. +" the case) in the first lines of the file, for example template files which +" were preprocessed or auto-generated files. Especially useful when the header +" is not displayed on the first screen, e.g. when the old position is +" restored. function! s:SearchForDoNotEditHeader() - if search('\cdo not edit', 'n') == 0 - \ || expand(':t') =~# '^.\?vimrc$' + " Only search the first 20 lines to prevent false positives, e.g. + " in scripts which write files containing this warning and ignore + " the case (\c). (Can't use search()'s {stopline} as we might not + " start searching from the top.) + let l:match = search('\cdo not edit', 'n') + if l:match == 0 || l:match > 20 return endif -- 2.44.1