diff options
authorTom Ryder <tom@sanctum.geek.nz>2018-01-21 22:02:09 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-01-21 22:02:09 +1300
commit2505497a1d382e09fbf68469c64fc7d3c00aa4c0 (patch)
parentRemove a baseless assertion I made in a config (diff)
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.
1 files 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
" Use different keys for global and local leaders
if has('eval')
@@ -29,3 +34,10 @@ if v:version >= 701
silent! colorscheme sahara
+" 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