aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-03 00:13:59 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-03 22:24:06 +1200
commitff891bbdc835da12894373bd918251a06a1de8f7 (patch)
treed948d6785473104cbf15dd0ade69ec9f40915f7b
parentUpdate vim-strip-trailing-whitespace v3.1.0 (diff)
downloaddotfiles-ff891bbdc835da12894373bd918251a06a1de8f7.tar.gz
dotfiles-ff891bbdc835da12894373bd918251a06a1de8f7.zip
Use autoloaded and correct function for &rtp split
-rw-r--r--vim/autoload/vimrc.vim47
-rw-r--r--vim/vimrc6
2 files changed, 49 insertions, 4 deletions
diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim
new file mode 100644
index 00000000..71b29d61
--- /dev/null
+++ b/vim/autoload/vimrc.vim
@@ -0,0 +1,47 @@
+" Split a string with a split character that can be escaped with another,
+" e.g. &runtimepath with commas and backslashes respectively
+function! vimrc#SplitEscaped(str, ...) abort
+
+ " Arguments to function
+ let str = a:str " String to split
+ let sep = a:0 >= 1 ? a:1 : ',' " Optional split char, default comma
+ let esc = a:0 >= 2 ? a:2 : '\' " Optional escape char, default backslash
+
+ " Get length of string, return empty list if it's zero
+ let len = strlen(str)
+ if !len
+ return []
+ endif
+
+ " Collect items into list by iterating characterwise
+ let list = [''] " List items
+ let idx = 0 " Offset in string
+ while idx < len
+
+ if str[idx] ==# sep
+
+ " This character is the item separator, and it wasn't escaped; start a
+ " new list item
+ call add(list, '')
+
+ else
+
+ " This character is the escape character, so we'll skip to the next
+ " character, if any, and add that; testing suggests that a terminal
+ " escape character on its own shouldn't be added
+ if str[idx] ==# esc
+ let idx += 1
+ endif
+ let list[-1] .= str[idx]
+
+ endif
+
+ " Bump index for next character
+ let idx += 1
+
+ endwhile
+
+ " Return the completed list
+ return list
+
+endfunction
diff --git a/vim/vimrc b/vim/vimrc
index 1612e3dd..ad582717 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -3,10 +3,8 @@
" Set an environment variable for the user runtime directory, if not already
" set; use the first element of &runtimepath, rather like 'spellfile'
-if !exists('$MYVIM')
- let $MYVIM = expand(
- \ strpart(&runtimepath, 0, stridx(&runtimepath, ','))
- \ )
+if !exists('$MYVIM') && strlen(&runtimepath) > 0
+ let $MYVIM = vimrc#SplitEscaped(&runtimepath)[0]
endif
" The all-important default indent settings; filetypes to tweak