diff options
author | Teddy Wing | 2017-02-23 23:43:27 +0100 |
---|---|---|
committer | Teddy Wing | 2017-02-23 23:45:14 +0100 |
commit | a669c67864951a979d83772b6f059ee5616ba66f (patch) | |
tree | cdff3ee864d3d6d77fa05a7f081cf64e887bf13e /bundle/insert-formatted-cal | |
parent | 39196d0d36ecc904e02369b261636fea3a0c6c38 (diff) | |
download | dotvim-a669c67864951a979d83772b6f059ee5616ba66f.tar.bz2 |
Create 'insert-formatted-cal' plugin
A plugin that will insert a given month from the `cal` program and
format it such that I can insert `*`s next to days to flag them.
I've been doing this manually for years and it finally seemed time to
automate the process.
Diffstat (limited to 'bundle/insert-formatted-cal')
-rw-r--r-- | bundle/insert-formatted-cal/autoload/insert_formatted_cal.vim | 47 | ||||
-rw-r--r-- | bundle/insert-formatted-cal/plugin/insert_formatted_cal.vim | 8 |
2 files changed, 55 insertions, 0 deletions
diff --git a/bundle/insert-formatted-cal/autoload/insert_formatted_cal.vim b/bundle/insert-formatted-cal/autoload/insert_formatted_cal.vim new file mode 100644 index 0000000..b2e0966 --- /dev/null +++ b/bundle/insert-formatted-cal/autoload/insert_formatted_cal.vim @@ -0,0 +1,47 @@ +" Read a month from the `cal` command and format it to add an extra space +" between each column and indent the calendar. +" +" Examples: +" InsertFormattedCal(3) +" InsertFormattedCal(3, 2017) +" +" Original: +" March 2017 +" Su Mo Tu We Th Fr Sa +" 1 2 3 4 +" 5 6 7 8 9 10 11 +" 12 13 14 15 16 17 18 +" 19 20 21 22 23 24 25 +" 26 27 28 29 30 31 +" +" Result: +" March 2017 +" Su Mo Tu We Th Fr Sa +" 1 2 3 4 +" 5 6 7 8 9 10 11 +" 12 13 14 15 16 17 18 +" 19 20 21 22 23 24 25 +" 26 27 28 29 30 31 +function! insert_formatted_cal#InsertFormattedCal(month, ...) + let year = a:0 ==# 0 ? system("date +'%Y'") : a:1 + + normal! m' + execute 'read !cal ' . a:month . ' ' . year + normal! '' + + " Add an extra space between columns + normal! 2j + silent .,+6s/ / /g + + " Remove an extra space from single-digit rows + normal! 4k + silent .,+2s/ / /g + + " Remove the extra initial space from single-digit rows + normal! k + silent .,+1s/^ // + + " Entab the calendar + normal! 3k + silent .,+6s/^/\t / +endfunction diff --git a/bundle/insert-formatted-cal/plugin/insert_formatted_cal.vim b/bundle/insert-formatted-cal/plugin/insert_formatted_cal.vim new file mode 100644 index 0000000..e1736f4 --- /dev/null +++ b/bundle/insert-formatted-cal/plugin/insert_formatted_cal.vim @@ -0,0 +1,8 @@ +" CalFormattedInsert +" Inserts the specified month from the `cal` command with special formatting +" to use as an in-Vim calendar. +" +" Examples: +" :CalFormattedInsert 3 +" :CalFormattedInsert 3 2017 +command! -nargs=+ CalFormattedInsert call insert_formatted_cal#InsertFormattedCal(<f-args>) |