" Vim file type plug-in " Author: Peter Odding " Last Change: May 16, 2013 " URL: http://peterodding.com/code/vim/notes/ if exists('b:did_ftplugin') finish else let b:did_ftplugin = 1 endif " Copy indent from previous line. {{{1 setlocal autoindent let b:undo_ftplugin = 'set autoindent<' " Set &tabstop and &shiftwidth options for bulleted lists. {{{1 setlocal tabstop=3 shiftwidth=3 expandtab let b:undo_ftplugin .= ' | set tabstop< shiftwidth< expandtab<' " Automatic formatting for bulleted lists. {{{1 let &l:comments = xolox#notes#get_comments_option() setlocal formatoptions=tcron let b:undo_ftplugin .= ' | set comments< formatoptions<' " Automatic text folding based on headings. {{{1 setlocal foldmethod=expr setlocal foldexpr=xolox#notes#foldexpr() setlocal foldtext=xolox#notes#foldtext() let b:undo_ftplugin .= ' | set foldmethod< foldexpr< foldtext<' " Enable concealing of notes syntax markers? {{{1 if has('conceal') setlocal conceallevel=3 let b:undo_ftplugin .= ' | set conceallevel<' endif " Change to jump to notes by name. {{{1 setlocal includeexpr=xolox#notes#include_expr(v:fname) let b:undo_ftplugin .= ' | set includeexpr<' " Enable completion of note titles using C-x C-u. {{{1 setlocal completefunc=xolox#notes#user_complete let b:undo_ftplugin .= ' | set completefunc<' " Enable completion of tag names using C-x C-o. {{{1 setlocal omnifunc=xolox#notes#omni_complete let b:undo_ftplugin .= ' | set omnifunc<' " Automatic completion of tag names after typing "@". {{{1 inoremap @ @ let b:undo_ftplugin .= ' | execute "iunmap @"' " Automatic completion of tag names should not interrupt the flow of typing, " for this we have to change the (unfortunately) global option &completeopt. set completeopt+=longest " Change double-dash to em-dash as it is typed. {{{1 if g:notes_smart_quotes && xolox#notes#unicode_enabled() inoremap -- — let b:undo_ftplugin .= ' | execute "iunmap --"' endif " Change plain quotes to curly quotes as they're typed. {{{1 if g:notes_smart_quotes inoremap ' xolox#notes#insert_quote(1) inoremap " xolox#notes#insert_quote(2) let b:undo_ftplugin .= ' | execute "iunmap ''"' let b:undo_ftplugin .= ' | execute ''iunmap "''' endif " Change ASCII style arrows to Unicode arrows. {{{1 if g:notes_smart_quotes && xolox#notes#unicode_enabled() inoremap -> → inoremap <- ← let b:undo_ftplugin .= ' | execute "iunmap ->"' let b:undo_ftplugin .= ' | execute "iunmap <-"' endif " Convert ASCII list bullets to Unicode bullets. {{{1 if g:notes_smart_quotes inoremap * xolox#notes#insert_bullet('*') inoremap - xolox#notes#insert_bullet('-') inoremap + xolox#notes#insert_bullet('+') let b:undo_ftplugin .= ' | execute "iunmap *"' let b:undo_ftplugin .= ' | execute "iunmap -"' let b:undo_ftplugin .= ' | execute "iunmap +"' endif " Format three asterisks as a horizontal ruler. {{{1 inoremap *** :call xolox#notes#insert_ruler() let b:undo_ftplugin .= ' | execute "iunmap ***"' " Indent list items using and ? {{{1 if g:notes_tab_indents inoremap :call xolox#notes#indent_list(1, line('.'), line('.')) snoremap :call xolox#notes#indent_list(1, line("'<"), line("'>"))gv let b:undo_ftplugin .= ' | execute "iunmap "' let b:undo_ftplugin .= ' | execute "sunmap "' inoremap :call xolox#notes#indent_list(-1, line('.'), line('.')) snoremap :call xolox#notes#indent_list(-1, line("'<"), line("'>"))gv let b:undo_ftplugin .= ' | execute "iunmap "' let b:undo_ftplugin .= ' | execute "sunmap "' endif " Indent list items using and ? {{{1 if g:notes_alt_indents inoremap :call xolox#notes#indent_list(1, line('.'), line('.')) snoremap :call xolox#notes#indent_list(1, line("'<"), line("'>"))gv let b:undo_ftplugin .= ' | execute "iunmap "' let b:undo_ftplugin .= ' | execute "sunmap "' inoremap :call xolox#notes#indent_list(-1, line('.'), line('.')) snoremap :call xolox#notes#indent_list(-1, line("'<"), line("'>"))gv let b:undo_ftplugin .= ' | execute "iunmap "' let b:undo_ftplugin .= ' | execute "sunmap "' endif " Automatically remove empty list items on Enter. {{{1 inoremap xolox#notes#cleanup_list() let b:undo_ftplugin .= ' | execute "iunmap "' " Shortcuts to create new notes from the selected text. {{{1 vnoremap en :NoteFromSelectedText let b:undo_ftplugin .= ' | execute "vunmap en"' vnoremap sn :SplitNoteFromSelectedText let b:undo_ftplugin .= ' | execute "vunmap sn"' vnoremap tn :TabNoteFromSelectedText let b:undo_ftplugin .= ' | execute "vunmap tn"' " }}}1 " This is currently the only place where a command is guaranteed to be " executed when the user edits a note. Maybe I shouldn't abuse this (it " doesn't feel right ;-) but for now it will do. call xolox#notes#recent#track() call xolox#notes#check_sync_title() " vim: ts=2 sw=2 et