From b7ce845692751f4de6d10da7e16904f1573b8cd2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 20 Jan 2018 22:54:31 +1300 Subject: Activate syntax settings conditionally Per an oft-made recommendation on /r/vim .vimrc review threads: > Re-sourcing the vimrc won't clobber any of your personal highlight > settings and the if part helps avoid unneeded re-execution/reprocessing. --- vim/config/syntax.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim index b493c0a9..5fdd1a82 100644 --- a/vim/config/syntax.vim +++ b/vim/config/syntax.vim @@ -2,8 +2,10 @@ if has('syntax') " Use syntax highlighting with 100 lines of context - silent! syntax enable - silent! syntax sync minlines=100 + if !has('g:syntax_on') + silent! syntax enable + silent! syntax sync minlines=100 + endif " If we can, detect a light background, but default to a dark one. This is " only because it's more likely the author of this configuration will be -- cgit v1.2.3 From 66b509d50adfdc75e3ba620c607d0540b0cff701 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 20 Jan 2018 23:05:50 +1300 Subject: Make entire syntax config dependent on load state --- vim/config/syntax.vim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim index 5fdd1a82..00004e35 100644 --- a/vim/config/syntax.vim +++ b/vim/config/syntax.vim @@ -1,11 +1,9 @@ " Options dependent on the syntax feature -if has('syntax') +if has('syntax') && !has('g:syntax_on') " Use syntax highlighting with 100 lines of context - if !has('g:syntax_on') - silent! syntax enable - silent! syntax sync minlines=100 - endif + silent! syntax enable + silent! syntax sync minlines=100 " If we can, detect a light background, but default to a dark one. This is " only because it's more likely the author of this configuration will be -- cgit v1.2.3 From a83cd7605f523f2419473b4c49c394bd11dfee74 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 20 Jan 2018 23:06:46 +1300 Subject: Remove a baseless assertion I made in a config Don't claim that syntax files tend to assume 'autoindent' is set, as it doesn't seem to be true. --- vim/config/whitespace.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim index 981def81..0d985f15 100644 --- a/vim/config/whitespace.vim +++ b/vim/config/whitespace.vim @@ -1,5 +1,4 @@ -" Adopt the indent of the last line on new lines; interestingly, plugins that -" do clever things with indenting will often assume this is set +" Adopt the indent of the last line on new lines set autoindent " Use spaces instead of tabs -- cgit v1.2.3 From 2505497a1d382e09fbf68469c64fc7d3c00aa4c0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Jan 2018 22:02:09 +1300 Subject: Tweak 'cpoptions' C flag instead of 'nocompatible' In order for the configuration to be successfully loaded, the only option in the vi 'cpoptions' settings for 'compatible' is "C". From :help 'cpoptions': > C Do not concatenate sourced lines that start with a backslash. > See line-continuation. With this flag removed from 'cpoptions' if 'compatible' does happen to be set, the configuration parses just fine, and then we can put it back at the end if we need to. This is a less aggressive approach than just turning off 'compatible' entirely if it happens to be set, whether because the user wanted it that way before loading the configuration or because Vim was started as ex(1). My plugins and ftplugins are all conditional on 'compatible' not being set, anyway. --- vim/vimrc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 5d195427..18363956 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1,5 +1,10 @@ -" Don't try to be vi-compatible, even if invoked as ex or with -u specified -set nocompatible +" If we're in compatible mode, ensure that the 'C' option that disallows line +" continuations is stripped out, as they're heavily used in this +" configuration for readability; we'll put it back later +if &compatible + let s:cpoptions_save = &cpoptions + set cpoptions-=C +endif " Use different keys for global and local leaders if has('eval') @@ -29,3 +34,10 @@ if v:version >= 701 silent! colorscheme sahara endif endif + +" If we're in compatible mode, put 'cpoptions' back the way we found it at the +" start of this configuration, even though it's the current year +if exists('s:cpoptions_save') + let &cpoptions = s:cpoptions_save + unlet s:cpoptions_save +endif -- cgit v1.2.3 From 164ec2c89ddafd8231565d26e843e2eacf47cd57 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Jan 2018 23:26:28 +1300 Subject: Remove 'mac' from 'fileformats' It seems unlikely that I'll ever edit a MacOS encoded file in my lifetime on the Unix and Windows systems to which these dotfiles are deployed, and when 'compatible' is set, the default empty value for this option breaks everything with a bunch of ^J characters in every god-fearing file. Not worth the trouble. --- vim/config/files.vim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vim/config/files.vim b/vim/config/files.vim index 7a23b4c5..61c3b6cb 100644 --- a/vim/config/files.vim +++ b/vim/config/files.vim @@ -18,10 +18,6 @@ if has('file_in_path') set path=** endif -" Try Mac line-endings if UNIX or DOS don't make sense; this has never -" happened to me but who knows, it might one day -set fileformats+=mac - " If the Vim buffer for a file doesn't have any changes and Vim detects the " file has been altered, quietly update it set autoread -- cgit v1.2.3 From ff621272fbc462d8c0a757f04166a0e8bbc213be Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Jan 2018 23:31:10 +1300 Subject: Break some continued lines in Vim indent files This will mean they load correctly when the 'C' flag preventing line-breaking is in 'cpoptions', and 'compatible' is set. --- vim/after/indent/vim.vim | 4 ++-- vim/indent/csv.vim | 3 +-- vim/indent/tsv.vim | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/vim/after/indent/vim.vim b/vim/after/indent/vim.vim index 0cb1d397..bfd92aeb 100644 --- a/vim/after/indent/vim.vim +++ b/vim/after/indent/vim.vim @@ -2,6 +2,6 @@ setlocal shiftwidth=2 setlocal softtabstop=2 if exists('b:undo_indent') - let b:undo_indent = b:undo_indent - \ . '|setlocal shiftwidth< softtabstop<' + let s:ui = '|setlocal shiftwidth< softtabstop<' + let b:undo_indent = b:undo_indent . s:ui endif diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim index d092838f..938bc99d 100644 --- a/vim/indent/csv.vim +++ b/vim/indent/csv.vim @@ -7,5 +7,4 @@ let b:did_indent = 1 " Manual indenting and literal tabs for CSVs setlocal noautoindent setlocal noexpandtab -let b:undo_indent - \ = 'setlocal autoindent< expandtab<' +let b:undo_indent = 'setlocal autoindent< expandtab<' diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim index 56721a4c..6f70276d 100644 --- a/vim/indent/tsv.vim +++ b/vim/indent/tsv.vim @@ -7,5 +7,4 @@ let b:did_indent = 1 " Manual indenting and literal tabs for TSVs setlocal noautoindent setlocal noexpandtab -let b:undo_indent - \ = 'setlocal autoindent< expandtab<' +let b:undo_indent = 'setlocal autoindent< expandtab<' -- cgit v1.2.3 From f8e01d5f70c020631257dbb6b144ee103330f7bd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Jan 2018 23:31:54 +1300 Subject: Join short-circuit line in detect_background.vim This makes the block work correctly when 'compatible' is set and 'C' is in 'cpoptions'. --- vim/autoload/detect_background.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim index c010dc53..e4163a43 100644 --- a/vim/autoload/detect_background.vim +++ b/vim/autoload/detect_background.vim @@ -9,8 +9,7 @@ " Author: Tom Ryder " License: Same as Vim itself " -if exists('g:loaded_detect_background') - \ || &compatible +if exists('g:loaded_detect_background') || &compatible finish endif let g:loaded_detect_background = 1 -- cgit v1.2.3 From ec775b023b0e83f413708d1bf294ab3abcaed666 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Jan 2018 23:34:32 +1300 Subject: Suspend 'C' from 'cpoptions' for sh syn extensions This allows me to use line-breaking to keep the file readable. --- vim/after/syntax/sh.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index 08dbd857..026e4ebd 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -1,3 +1,9 @@ +" Support line continuation for this file +if &compatible + let s:cpoptions_save = &cpoptions + set cpoptions-=C +endif + " If we know we have another shell type, clear away the others completely, now " that core syntax/sh.vim is done prodding /bin/sh to determine the system " shell type (which I don't care about). @@ -210,3 +216,9 @@ if exists('b:is_bash') \ variables \ wait endif + +" Restore 'cpoptions' setting if we touched it +if exists('s:cpoptions_save') + let &cpoptions = s:cpoptions_save + unlet s:cpoptions_save +endif -- cgit v1.2.3