From cdb380156ff7ee614cbfb2d2bc6f736f2d856f0d Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 27 Dec 2022 07:24:52 -0500 Subject: [PATCH] Don't override user configured value of options While `:runtime plugin/sensible.vim` does allow for effectively superseding any option set by sensible.vim, it has never sat right with me that this was necessary. This change attempt to use the output of `:verbose set` to determine if an option should be overridden or not. Excluded from this change is options we alter, rather than override, since a user could conceivably have their own alterations that do not conflict with sensible.vim. If any of these alterations were to receive pushback, I would reconsider this decision. References: https://github.com/tpope/vim-sensible/issues/129 References: https://github.com/tpope/vim-sensible/issues/88 --- plugin/sensible.vim | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/plugin/sensible.vim b/plugin/sensible.vim index d8e6ae4..fe9b51b 100644 --- a/plugin/sensible.vim +++ b/plugin/sensible.vim @@ -17,14 +17,26 @@ endif " Use :help 'option' to see the documentation for the given option. -if empty(&backspace) +" Check if an option was set from a file in $HOME. This lets us avoid +" overriding options in the user's vimrc, but still override options in the +" system vimrc. +function! s:MaySet(option) abort + redir => out + silent verbose execute 'setglobal' a:option . '?' + redir END + return out !~# ' \~[\/]' +endfunction + +if s:MaySet('backspace') set backspace=indent,eol,start endif " Disable completing keywords in included files (e.g., #include in C). When " configured properly, this can result in the slow, recursive scanning of " hundreds of files of dubious relevance. set complete-=i -set smarttab +if s:MaySet('smarttab') + set smarttab +endif set nrformats-=octal @@ -35,23 +47,29 @@ if !has('nvim') && &ttimeoutlen == -1 set ttimeoutlen=100 endif -set incsearch +if has('reltime') && s:MaySet('incsearch') + set incsearch +endif " Use CTRL-L to clear the highlighting of 'hlsearch' (off by default) and call " :diffupdate. if maparg('', 'n') ==# '' nnoremap :nohlsearch=has('diff')?'diffupdate':'' endif -if &laststatus < 2 +if s:MaySet('laststatus') set laststatus=2 endif -set ruler -set wildmenu +if s:MaySet('ruler') + set ruler +endif +if s:MaySet('wildmenu') + set wildmenu +endif -if !&scrolloff +if s:MaySet('scrolloff') set scrolloff=1 endif -if !&sidescrolloff +if s:MaySet('sidescrolloff') set sidescrolloff=5 endif set display+=lastline @@ -59,7 +77,7 @@ if has('patch-7.4.2109') set display+=truncate endif -if &listchars ==# 'eol:$' +if s:MaySet('listchars') set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+ endif @@ -74,12 +92,14 @@ if has('path_extra') && (',' . &g:tags . ',') =~# ',\./tags,' setglobal tags-=./tags tags-=./tags; tags^=./tags; endif -set autoread +if s:MaySet('autoread') + set autoread +endif -if &history < 1000 +if s:MaySet('history') set history=1000 endif -if &tabpagemax < 50 +if s:MaySet('tabpagemax') set tabpagemax=50 endif @@ -103,7 +123,7 @@ if &shell =~# 'fish$' && (v:version < 704 || v:version == 704 && !has('patch276' endif " Disable a legacy behavior that can break plugin maps. -if has('langmap') && exists('+langremap') && &langremap +if has('langmap') && exists('+langremap') && &langremap && s:MaySet('langremap') set nolangremap endif