From f97a710bb105fb9f24faf1bc2c21c1b450c0bf5b Mon Sep 17 00:00:00 2001 From: jakeroggenbuck Date: Mon, 8 Mar 2021 15:36:07 -0800 Subject: [PATCH 1/5] Add clip copy --- plugin/draft.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/draft.vim b/plugin/draft.vim index 4bc3269..261f5e9 100644 --- a/plugin/draft.vim +++ b/plugin/draft.vim @@ -66,6 +66,11 @@ func! g:ChangeFileExt(ext) :e! endfunc +func! g:ClipDraft() + let s:filename = expand('%:p') + command! "xclip -sel clip " . s:filename +endfunc + command! -bar -bang -nargs=? Draft call NewDraft() command! -bar -bang -nargs=? DraftExt call ChangeFileExt() command! -bar -bang OpenDrafts call OpenDrafts() From 851ea95bb2dac818bc0b4f9ac665bc4382d274f6 Mon Sep 17 00:00:00 2001 From: jakeroggenbuck Date: Mon, 8 Mar 2021 15:43:39 -0800 Subject: [PATCH 2/5] Fix command --- plugin/draft.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/draft.vim b/plugin/draft.vim index 261f5e9..05397b7 100644 --- a/plugin/draft.vim +++ b/plugin/draft.vim @@ -67,8 +67,8 @@ func! g:ChangeFileExt(ext) endfunc func! g:ClipDraft() - let s:filename = expand('%:p') - command! "xclip -sel clip " . s:filename + let s:filename = + command! xclip -sel clip . expand('%:p') endfunc command! -bar -bang -nargs=? Draft call NewDraft() From 7a942fbe294b1f70ca711732b5ea58be99d4557e Mon Sep 17 00:00:00 2001 From: jakeroggenbuck Date: Mon, 8 Mar 2021 15:51:17 -0800 Subject: [PATCH 3/5] Fix clip command --- plugin/draft.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/draft.vim b/plugin/draft.vim index 05397b7..e5c30d6 100644 --- a/plugin/draft.vim +++ b/plugin/draft.vim @@ -59,8 +59,7 @@ EOF endfunc func! g:ChangeFileExt(ext) - let s:filename = expand('%:p') - execute "file " . s:filename . a:ext + execute "file " . expand('%:p') . a:ext " Reload buffer :w :e! @@ -68,9 +67,10 @@ endfunc func! g:ClipDraft() let s:filename = - command! xclip -sel clip . expand('%:p') + execute ':!command xclip -sel clip ' . expand('%:p') endfunc command! -bar -bang -nargs=? Draft call NewDraft() command! -bar -bang -nargs=? DraftExt call ChangeFileExt() +command! -bar -bang DraftCopy call ClipDraft() command! -bar -bang OpenDrafts call OpenDrafts() From 5176586710185fc18467668cdea0f6ab4ffa7075 Mon Sep 17 00:00:00 2001 From: jakeroggenbuck Date: Mon, 8 Mar 2021 15:53:44 -0800 Subject: [PATCH 4/5] Remove leftover line, oops --- plugin/draft.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/draft.vim b/plugin/draft.vim index e5c30d6..d4e1d10 100644 --- a/plugin/draft.vim +++ b/plugin/draft.vim @@ -66,7 +66,6 @@ func! g:ChangeFileExt(ext) endfunc func! g:ClipDraft() - let s:filename = execute ':!command xclip -sel clip ' . expand('%:p') endfunc From 38a681031df2bb98571e4662075b99b8ed9ef770 Mon Sep 17 00:00:00 2001 From: jakeroggenbuck Date: Mon, 8 Mar 2021 16:13:16 -0800 Subject: [PATCH 5/5] Add more docs --- README.md | 39 ++++++++++++++++++++++++++++++++++++--- plugin/draft.vim | 30 +++++++++++++++++------------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 23f959c..e366f6e 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,25 @@ nnoremap z :call OpenDrafts() ``` ## Use -- Open vim and run `:Draft` or `:Draft ""` to auto name with the date and time -- Edit the file extension `:DraftExt .md` to change the file to markdown + + +### Commands + +|-------------------------|-------------------------------------------------| +| Command | Description | +| `:Draft` | Open a blanck new draft | +| `:Draft <title>` | Open a draft with a title | +| `:DraftExt <extension>` | Change the file extension of a draft | +| `:Drafts` | Open the draft directory in a buffer | +| `:DraftCopy` | Copy the contents of the draft to the clipboard | +|-------------------------|-------------------------------------------------| + +### More info + +- New draft: run `:Draft` or `:Draft "<Title>"` to auto name with the date and time +- Edit the file extension: run `:DraftExt .md` to change the file to markdown +- Open the drafts directory: run `:Drafts` +- Copy the contents of the current draft `:DraftCopy` - Draft will open a new file in a specific directory, with a unique name - The file will be based on a template with stuff like the title and datetime @@ -49,9 +66,25 @@ nnoremap <Leader>z :call OpenDrafts()<CR> #### Vundle `Plugin 'jakeroggenbuck/draft.vim'` +## Versions + +#### 0.1 draft.vim - not fully functional, just a concept + +- Open a new draft with a name +- List the draft but no reopening them + +#### 0.2 draft.vim - first complete version + +- Add `OpenDrafts()` +- Add new command aliases `Draft`, `DraftExt` + +#### 0.3 draft.vim - more features + +- Add `ClipDraft()` or `DraftCopy` +- Add `Buffer reload for DraftExt` ## TODO -- Keybind or function call to copy contents with and without header to file +- Keybind or function call to copy contents without header to file - Make a convert to pdf for markdown ## Maybe TODO diff --git a/plugin/draft.vim b/plugin/draft.vim index d4e1d10..21b9a42 100644 --- a/plugin/draft.vim +++ b/plugin/draft.vim @@ -1,6 +1,6 @@ " draft.vim - Quickly writeup and save drafts for messaging apps in your favorite editor " Authors: Jake Roggenbuck -" Version: 0.2 +" Version: 0.3 " License: MIT if exists('g:loaded_draft_plugin') || &compatible || v:version < 700 @@ -11,10 +11,25 @@ let g:loaded_draft_plugin = 1 let s:plugin_root_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h') + func! g:OpenDrafts() execute ":edit" . g:drafts_directory endfunc +func! g:ChangeFileExt(ext) + execute "file " . expand('%:p') . a:ext + " Reload buffer + :w + :e! +endfunc + +func! g:ClipDraft() + " Copy the contents of the file to clipboard + :w + execute ':silent !command xclip -sel clip ' . expand('%:p') +endfunc + + func! s:SourcePython() py3 << EOF import sys @@ -58,18 +73,7 @@ for file in list_drafts(drafts_directory): EOF endfunc -func! g:ChangeFileExt(ext) - execute "file " . expand('%:p') . a:ext - " Reload buffer - :w - :e! -endfunc - -func! g:ClipDraft() - execute ':!command xclip -sel clip ' . expand('%:p') -endfunc - command! -bar -bang -nargs=? Draft call NewDraft(<q-args>) command! -bar -bang -nargs=? DraftExt call ChangeFileExt(<q-args>) command! -bar -bang DraftCopy call ClipDraft() -command! -bar -bang OpenDrafts call OpenDrafts() +command! -bar -bang Drafts call OpenDrafts()