Skip to content

Commit

Permalink
Don't override user configured value of options
Browse files Browse the repository at this point in the history
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: #129
References: #88
  • Loading branch information
tpope committed Dec 29, 2022
1 parent c597927 commit cdb3801
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions plugin/sensible.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -35,31 +47,37 @@ 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('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
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
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

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit cdb3801

Please sign in to comment.