diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-16 19:45:40 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-16 19:49:13 +1200 |
commit | d03a9d7b3f724706775c793df7b6b627ea4ef60a (patch) | |
tree | a4a1d06b41dd8475622b43434968d7daaaa67d04 | |
parent | Document choice of format for PutDate() (diff) | |
download | dotfiles-d03a9d7b3f724706775c793df7b6b627ea4ef60a.tar.gz dotfiles-d03a9d7b3f724706775c793df7b6b627ea4ef60a.zip |
Consolidate utc.vim and put_date.vim into latter
-rw-r--r-- | vim/autoload/put_date.vim | 19 | ||||
-rw-r--r-- | vim/autoload/utc.vim | 4 | ||||
-rw-r--r-- | vim/plugin/put_date.vim | 5 | ||||
-rw-r--r-- | vim/plugin/utc.vim | 6 | ||||
-rw-r--r-- | vim/vimrc | 6 |
5 files changed, 24 insertions, 16 deletions
diff --git a/vim/autoload/put_date.vim b/vim/autoload/put_date.vim new file mode 100644 index 00000000..2b618632 --- /dev/null +++ b/vim/autoload/put_date.vim @@ -0,0 +1,19 @@ +let s:rfc_2822 = '%a, %d %b %Y %T %z' + +function! put_date#(line, bang, ...) abort + let line = a:line + let utc = a:bang ==# '!' + let format = a:0 + \ ? substitute(a:1, '\a', '%&', 'g') + \ : s:rfc_2822 + if utc + if exists('$TZ') + let tz = $TZ + endif + let $TZ = 'UTC' + endif + execute line.'put =strftime(format)' + if exists('tz') + let $TZ = tz + endif +endfunction diff --git a/vim/autoload/utc.vim b/vim/autoload/utc.vim deleted file mode 100644 index 1a464342..00000000 --- a/vim/autoload/utc.vim +++ /dev/null @@ -1,4 +0,0 @@ -function! utc#(command) abort - let tz = expand('$TZ') - let $TZ = 'UTC' | execute a:command | let $TZ = tz -endfunction diff --git a/vim/plugin/put_date.vim b/vim/plugin/put_date.vim index 486171a3..e54d6054 100644 --- a/vim/plugin/put_date.vim +++ b/vim/plugin/put_date.vim @@ -2,6 +2,5 @@ if exists('loaded_put_date') finish endif let loaded_put_date = 1 -let s:rfc_2822 = '%a, %d %b %Y %T %z' -command! -bar -range PutDate - \ <line1>put =strftime(s:rfc_2822) +command! -bang -bar -nargs=* -range PutDate + \ call put_date#(<q-line1>, <q-bang>, <q-args>) diff --git a/vim/plugin/utc.vim b/vim/plugin/utc.vim deleted file mode 100644 index 9b8b647a..00000000 --- a/vim/plugin/utc.vim +++ /dev/null @@ -1,6 +0,0 @@ -if exists('loaded_utc') - finish -endif -let loaded_utc = 1 -command! -bar -complete=command -nargs=1 UTC - \ call utc#(<q-args>) @@ -1384,15 +1384,15 @@ nnoremap <Leader>t nnoremap <Leader>T \ :<C-U>setlocal filetype=<CR> -" These mappings use my put_date.vim and utc.vim plugins for date insertion -" into the buffer. +" These mappings use my put_date.vim plugin for date insertion into the +" buffer. "" Leader,d inserts the local date (RFC 2822) nnoremap <Leader>d \ :PutDate<CR> "" Leader,D inserts the UTC date (RFC 2822) nnoremap <Leader>D - \ :<Home>UTC<End> PutDate<CR> + \ :PutDate!<CR> " This group contains mappings that are to do with file and path management " relative to the current buffer. The Leader,P mapping that creates |