Created
April 17, 2016 15:04
-
-
Save durcheinandr/5088c90872514593ec39e22106e90aba to your computer and use it in GitHub Desktop.
Add Sidenotes to every file. Sidenotes are sidecar files in a custom directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" let g:snotepath = '/path/to/your/sidenotes/' | |
" let g:snoteext = 'md' | |
" defaults for sidenotes-directory and extension | |
if !exists('g:snotepath') | |
let g:snotepath = $HOME . '/sidenotes/' | |
endif | |
if !exists('g:snoteext') | |
let g:snoteext ='markdown' | |
endif | |
if !isdirectory(g:snotepath) | |
execute 'silent! !mkdir -p ' . g:snotepath | |
endif | |
function! sidenote#file() | |
let g:snoteref = expand('%:p') | |
let b:snotefilename = substitute(expand('%:p'), '/', '%', 'g') | |
let b:snotefile = expand(g:snotepath . b:snotefilename . '.' . g:snoteext) | |
if expand('%:p:h') != g:snotepath | |
if filereadable(b:snotefile) | |
execute 'vsplit ' . fnameescape(expand(b:snotefile)) | |
else | |
execute 'silent! !touch ' . fnameescape(expand(b:snotefile)) | |
execute 'vsplit ' . fnameescape(expand(b:snotefile)) | |
silent! put = 'Sidenote for file: ' . expand(g:snoteref) | |
silent! put = '' | |
endif | |
redraw! | |
endif | |
endfunction | |
command! SideNote call sidenote#file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" statusline indicator for sidenote | |
" to include indicator to the statusline insert following line to | |
" ~/.vimrc | |
" set statusline+='%{SidenoteStatline()}' | |
function! sidenote#statline() | |
let g:snoteref = expand('%:p') | |
let b:snotefilename = substitute(expand('%:p'), '/', '%', 'g') | |
let b:snotefile = expand(g:snotepath . b:snotefilename . '.' . g:snoteext) | |
let g:snote_availible = '' | |
if filereadable(b:snotefile) | |
let g:snote_availible = '[SN]' | |
endif | |
return g:snote_availible | |
endfunction | |
set statusline+='%{SidenoteStatline()}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment