Move into autoload

Mon, 09 Jan 2017 15:30:39 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 09 Jan 2017 15:30:39 -0500
changeset 470
4c2db769baac
parent 469
fbf39fa1349c
child 471
5df697de1d9e

Move into autoload

.vim/autoload/vimrc.vim file | annotate | diff | comparison | revisions
.vimrc file | annotate | diff | comparison | revisions
new file mode 100644
--- /dev/null
+++ b/.vim/autoload/vimrc.vim
@@ -0,0 +1,21 @@
+
+function! vimrc#AutoFmtToggle() abort
+  if &formatoptions =~ 'a'
+    setl fo-=a
+    echo '-a'
+  else
+    setl fo+=a
+    echo '+a'
+  endif
+endfunction
+
+" Make paths when writing, as necessary
+function! vimrc#MkNonExDir(file, buf) abort
+  if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
+    let dir=fnamemodify(a:file, ':h')
+    if !isdirectory(dir)
+      call mkdir(dir, 'p')
+    endif
+  endif
+endfunction
+
--- a/.vimrc
+++ b/.vimrc
@@ -143,17 +143,7 @@ map <leader>te :Tabularize first_eq<CR>
 map <leader>tc :Tabularize first_colon<CR>
 map <leader>tm :Tabularize methods<CR>
 
-function! AutoFmtToggle()
-  if &formatoptions =~ 'a'
-    setl fo-=a
-    echo '-a'
-  else
-    setl fo+=a
-    echo '+a'
-  endif
-endfunction
-
-map <silent> <leader>a :call AutoFmtToggle()<CR>
+map <silent> <leader>a :call vimrc#AutoFmtToggle()<CR>
 
 cabbr Q q
 cabbr W w
@@ -325,18 +315,9 @@ augroup vimrc
 augroup END
 
 " Make paths when writing, as necessary
-function! s:MkNonExDir(file, buf)
-  if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
-    let dir=fnamemodify(a:file, ':h')
-    if !isdirectory(dir)
-      call mkdir(dir, 'p')
-    endif
-  endif
-endfunction
-
 augroup AutoMkdir
   autocmd!
-  autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
+  autocmd BufWritePre * :call vimrc#MkNonExDir(expand('<afile>'), +expand('<abuf>'))
 augroup END
 
 " https://mjj.io/2015/01/27/encrypting-files-with-gpg-and-vim/
@@ -565,4 +546,3 @@ else
   endif
 endif
 
-

mercurial