Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,25 @@ nnoremap <Leader>z :call OpenDrafts()<CR>
```

## Use
- Open vim and run `:Draft` or `:Draft "<Title>"` 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

Expand All @@ -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
Expand Down
28 changes: 18 additions & 10 deletions plugin/draft.vim
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -58,14 +73,7 @@ for file in list_drafts(drafts_directory):
EOF
endfunc

func! g:ChangeFileExt(ext)
let s:filename = expand('%:p')
execute "file " . s:filename . a:ext
" Reload buffer
:w
:e!
endfunc

command! -bar -bang -nargs=? Draft call NewDraft(<q-args>)
command! -bar -bang -nargs=? DraftExt call ChangeFileExt(<q-args>)
command! -bar -bang OpenDrafts call OpenDrafts()
command! -bar -bang DraftCopy call ClipDraft()
command! -bar -bang Drafts call OpenDrafts()