diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-03 00:13:59 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-03 22:24:06 +1200 |
commit | ff891bbdc835da12894373bd918251a06a1de8f7 (patch) | |
tree | d948d6785473104cbf15dd0ade69ec9f40915f7b /vim/autoload | |
parent | Update vim-strip-trailing-whitespace v3.1.0 (diff) | |
download | dotfiles-ff891bbdc835da12894373bd918251a06a1de8f7.tar.gz dotfiles-ff891bbdc835da12894373bd918251a06a1de8f7.zip |
Use autoloaded and correct function for &rtp split
Diffstat (limited to 'vim/autoload')
-rw-r--r-- | vim/autoload/vimrc.vim | 47 |
1 files changed, 47 insertions, 0 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 |