2018-04-20 07:03:53 +02:00
|
|
|
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
2010-01-20 01:00:00 +01:00
|
|
|
" Vimwiki plugin file
|
2015-02-23 12:10:42 +01:00
|
|
|
" Home: https://github.com/vimwiki/vimwiki/
|
2010-01-20 01:00:00 +01:00
|
|
|
" GetLatestVimScripts: 2226 1 :AutoInstall: vimwiki
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Clause: load only onces
|
2019-12-21 04:41:03 +01:00
|
|
|
if exists('g:loaded_vimwiki') || &compatible
|
2010-01-20 01:00:00 +01:00
|
|
|
finish
|
|
|
|
endif
|
2014-02-24 12:16:23 +01:00
|
|
|
let g:loaded_vimwiki = 1
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-06-12 20:55:56 +02:00
|
|
|
" Set to version number for release, otherwise -1 for dev-branch
|
2020-06-01 10:46:41 +02:00
|
|
|
let s:plugin_vers = -1
|
2018-06-12 20:55:56 +02:00
|
|
|
|
|
|
|
" Get the directory the script is installed in
|
|
|
|
let s:plugin_dir = expand('<sfile>:p:h:h')
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Save peace in the galaxy
|
2019-12-21 04:41:03 +01:00
|
|
|
let s:old_cpo = &cpoptions
|
|
|
|
set cpoptions&vim
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Save autowriteall varaible state
|
2018-05-15 21:48:58 +02:00
|
|
|
if exists('g:vimwiki_autowriteall')
|
|
|
|
let s:vimwiki_autowriteall_saved = g:vimwiki_autowriteall
|
|
|
|
else
|
|
|
|
let s:vimwiki_autowriteall_saved = 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Autocommand called when the cursor leaves the buffer
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:setup_buffer_leave() abort
|
2016-12-25 21:35:56 +01:00
|
|
|
" don't do anything if it's not managed by Vimwiki (that is, when it's not in
|
|
|
|
" a registered wiki and not a temporary wiki)
|
2016-12-28 22:17:08 +01:00
|
|
|
if vimwiki#vars#get_bufferlocal('wiki_nr') == -1
|
2016-12-25 21:35:56 +01:00
|
|
|
return
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
2016-12-25 21:35:56 +01:00
|
|
|
let &autowriteall = s:vimwiki_autowriteall_saved
|
2014-11-26 14:35:38 +01:00
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
if !empty(vimwiki#vars#get_global('menu'))
|
2016-12-25 21:35:56 +01:00
|
|
|
exe 'nmenu disable '.vimwiki#vars#get_global('menu').'.Table'
|
2014-11-26 14:35:38 +01:00
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2014-11-26 14:35:38 +01:00
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Create a new temporary wiki for the current buffer
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:create_temporary_wiki() abort
|
2016-12-25 21:35:56 +01:00
|
|
|
let path = expand('%:p:h')
|
|
|
|
let ext = '.'.expand('%:e')
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2016-12-25 21:35:56 +01:00
|
|
|
let syntax_mapping = vimwiki#vars#get_global('ext2syntax')
|
|
|
|
if has_key(syntax_mapping, ext)
|
|
|
|
let syntax = syntax_mapping[ext]
|
|
|
|
else
|
|
|
|
let syntax = vimwiki#vars#get_wikilocal_default('syntax')
|
2012-06-07 02:00:00 +02:00
|
|
|
endif
|
2010-02-23 01:00:00 +01:00
|
|
|
|
2016-12-25 21:35:56 +01:00
|
|
|
let new_temp_wiki_settings = {'path': path,
|
|
|
|
\ 'ext': ext,
|
|
|
|
\ 'syntax': syntax,
|
|
|
|
\ }
|
2013-04-19 05:46:58 +02:00
|
|
|
|
2016-12-25 21:35:56 +01:00
|
|
|
call vimwiki#vars#add_temporary_wiki(new_temp_wiki_settings)
|
2018-05-09 22:02:07 +02:00
|
|
|
|
|
|
|
" Update the wiki number of the current buffer, because it may have changed when adding this
|
|
|
|
" temporary wiki.
|
|
|
|
call vimwiki#vars#set_bufferlocal('wiki_nr', vimwiki#base#find_wiki(expand('%:p')))
|
2016-12-25 21:35:56 +01:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Autocommand called when Vim opens a new buffer with a known wiki
|
2018-02-15 18:38:39 +01:00
|
|
|
" extension. Both when the buffer has never been opened in this session and
|
|
|
|
" when it has.
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:setup_new_wiki_buffer() abort
|
2016-12-25 21:35:56 +01:00
|
|
|
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
|
|
|
|
if wiki_nr == -1 " it's not in a known wiki directory
|
|
|
|
if vimwiki#vars#get_global('global_ext')
|
|
|
|
call s:create_temporary_wiki()
|
|
|
|
else
|
|
|
|
" the user does not want a temporary wiki, so do nothing
|
|
|
|
return
|
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
endif
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2018-02-14 06:53:46 +01:00
|
|
|
if vimwiki#vars#get_wikilocal('maxhi')
|
2020-05-26 20:05:42 +02:00
|
|
|
call vimwiki#vars#set_bufferlocal('existing_wikifiles', vimwiki#base#get_wikilinks(wiki_nr, 1, ''))
|
2018-02-14 06:53:46 +01:00
|
|
|
call vimwiki#vars#set_bufferlocal('existing_wikidirs',
|
|
|
|
\ vimwiki#base#get_wiki_directories(wiki_nr))
|
|
|
|
endif
|
|
|
|
|
2017-11-11 21:52:07 +01:00
|
|
|
" this makes that ftplugin/vimwiki.vim and afterwards syntax/vimwiki.vim are
|
|
|
|
" sourced
|
2019-04-12 15:42:49 +02:00
|
|
|
call vimwiki#u#ft_set()
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Autocommand called when the cursor enters the buffer
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:setup_buffer_enter() abort
|
2016-12-25 21:35:56 +01:00
|
|
|
" don't do anything if it's not managed by Vimwiki (that is, when it's not in
|
|
|
|
" a registered wiki and not a temporary wiki)
|
2016-12-28 22:17:08 +01:00
|
|
|
if vimwiki#vars#get_bufferlocal('wiki_nr') == -1
|
2016-12-25 21:35:56 +01:00
|
|
|
return
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
2019-04-22 16:39:11 +02:00
|
|
|
call s:set_global_options()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Autocommand called when the buffer enters a window or when running a diff
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:setup_buffer_win_enter() abort
|
2019-04-22 16:39:11 +02:00
|
|
|
" don't do anything if it's not managed by Vimwiki (that is, when it's not in
|
|
|
|
" a registered wiki and not a temporary wiki)
|
|
|
|
if vimwiki#vars#get_bufferlocal('wiki_nr') == -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2019-04-12 15:42:49 +02:00
|
|
|
if !vimwiki#u#ft_is_vw()
|
|
|
|
call vimwiki#u#ft_set()
|
2011-06-11 02:00:00 +02:00
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
call s:set_windowlocal_options()
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Help syntax reloading
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:setup_cleared_syntax() abort
|
2018-04-20 07:03:53 +02:00
|
|
|
" highlight groups that get cleared
|
2012-06-07 02:00:00 +02:00
|
|
|
" on colorscheme change because they are not linked to Vim-predefined groups
|
|
|
|
hi def VimwikiBold term=bold cterm=bold gui=bold
|
|
|
|
hi def VimwikiItalic term=italic cterm=italic gui=italic
|
|
|
|
hi def VimwikiBoldItalic term=bold cterm=bold gui=bold,italic
|
|
|
|
hi def VimwikiUnderline gui=underline
|
2016-12-21 19:43:34 +01:00
|
|
|
if vimwiki#vars#get_global('hl_headers') == 1
|
2012-06-07 02:00:00 +02:00
|
|
|
for i in range(1,6)
|
2018-02-15 18:38:39 +01:00
|
|
|
execute 'hi def VimwikiHeader'.i.' guibg=bg guifg='
|
2019-12-21 04:41:03 +01:00
|
|
|
\ . vimwiki#vars#get_global('hcolor_guifg_'.&background)[i-1]
|
|
|
|
\ .' gui=bold ctermfg='.vimwiki#vars#get_global('hcolor_ctermfg_'.&background)[i-1]
|
2018-02-15 18:38:39 +01:00
|
|
|
\ .' term=bold cterm=bold'
|
2012-06-07 02:00:00 +02:00
|
|
|
endfor
|
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Return: list of extension known vy vimwiki
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:vimwiki_get_known_extensions() abort
|
2015-01-09 22:23:21 +01:00
|
|
|
" Getting all extensions that different wikis could have
|
|
|
|
let extensions = {}
|
2016-12-22 21:00:19 +01:00
|
|
|
for idx in range(vimwiki#vars#number_of_wikis())
|
|
|
|
let ext = vimwiki#vars#get_wikilocal('ext', idx)
|
|
|
|
let extensions[ext] = 1
|
2015-01-09 22:23:21 +01:00
|
|
|
endfor
|
2016-12-21 19:43:34 +01:00
|
|
|
" append extensions from g:vimwiki_ext2syntax
|
|
|
|
for ext in keys(vimwiki#vars#get_global('ext2syntax'))
|
2015-01-09 22:23:21 +01:00
|
|
|
let extensions[ext] = 1
|
|
|
|
endfor
|
|
|
|
return keys(extensions)
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2015-01-09 22:23:21 +01:00
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
|
|
|
|
" Set settings which are global for Vim, but should only be executed for
|
|
|
|
" Vimwiki buffers. So they must be set when the cursor enters a Vimwiki buffer
|
|
|
|
" and reset when the cursor leaves the buffer.
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:set_global_options() abort
|
2018-02-15 18:38:39 +01:00
|
|
|
let s:vimwiki_autowriteall_saved = &autowriteall
|
|
|
|
let &autowriteall = vimwiki#vars#get_global('autowriteall')
|
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
if !empty(vimwiki#vars#get_global('menu'))
|
2018-02-15 18:38:39 +01:00
|
|
|
exe 'nmenu enable '.vimwiki#vars#get_global('menu').'.Table'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
" Set settings which are local to a window. In a new tab they would be reset to
|
|
|
|
" Vim defaults. So we enforce our settings here when the cursor enters a
|
|
|
|
" Vimwiki buffer.
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:set_windowlocal_options() abort
|
2018-08-07 21:39:54 +02:00
|
|
|
if !&diff " if Vim is currently in diff mode, don't interfere with its folding
|
|
|
|
let foldmethod = vimwiki#vars#get_global('folding')
|
|
|
|
if foldmethod =~? '^expr.*'
|
|
|
|
setlocal foldmethod=expr
|
|
|
|
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
|
|
|
|
setlocal foldtext=VimwikiFoldText()
|
|
|
|
elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*'
|
|
|
|
setlocal foldmethod=expr
|
|
|
|
setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
|
|
|
|
setlocal foldtext=VimwikiFoldText()
|
|
|
|
elseif foldmethod =~? '^syntax.*'
|
|
|
|
setlocal foldmethod=syntax
|
|
|
|
setlocal foldtext=VimwikiFoldText()
|
|
|
|
elseif foldmethod =~? '^custom.*'
|
|
|
|
" do nothing
|
|
|
|
else
|
|
|
|
setlocal foldmethod=manual
|
|
|
|
normal! zE
|
|
|
|
endif
|
2018-02-15 18:38:39 +01:00
|
|
|
endif
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
if exists('+conceallevel')
|
2020-06-01 10:20:00 +02:00
|
|
|
let &l:conceallevel = vimwiki#vars#get_global('conceallevel')
|
2018-02-15 18:38:39 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
if vimwiki#vars#get_global('auto_chdir')
|
|
|
|
exe 'lcd' vimwiki#vars#get_wikilocal('path')
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Echo vimwiki version
|
|
|
|
" Called by :VimwikiShowVersion
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:get_version() abort
|
2019-04-01 19:59:43 +02:00
|
|
|
if s:plugin_vers != -1
|
2019-12-21 04:41:03 +01:00
|
|
|
echo 'Stable version: ' . string(s:plugin_vers)
|
2018-06-12 20:55:56 +02:00
|
|
|
else
|
2019-12-21 04:41:03 +01:00
|
|
|
let l:plugin_rev = system('git --git-dir ' . s:plugin_dir . '/.git rev-parse --short HEAD')
|
|
|
|
let l:plugin_branch = system('git --git-dir ' . s:plugin_dir . '/.git rev-parse --abbrev-ref HEAD')
|
|
|
|
let l:plugin_date = system('git --git-dir ' . s:plugin_dir . '/.git show -s --format=%ci')
|
2018-06-12 20:55:56 +02:00
|
|
|
if v:shell_error == 0
|
2020-05-14 04:43:41 +02:00
|
|
|
echo 'Os: ' . vimwiki#u#os_name()
|
|
|
|
echo 'Vim: ' . v:version
|
2019-12-21 04:41:03 +01:00
|
|
|
echo 'Branch: ' . l:plugin_branch
|
|
|
|
echo 'Revision: ' . l:plugin_rev
|
|
|
|
echo 'Date: ' . l:plugin_date
|
2018-06-12 20:55:56 +02:00
|
|
|
else
|
2019-12-21 04:41:03 +01:00
|
|
|
echo 'Unknown version'
|
2018-06-12 20:55:56 +02:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" Initialization of Vimwiki starts here.
|
|
|
|
" Make sure everything below does not cause autoload/vimwiki/base.vim
|
|
|
|
" to be loaded
|
2016-12-21 19:43:34 +01:00
|
|
|
call vimwiki#vars#init()
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" Define callback functions which the user can redefine
|
2019-12-21 04:41:03 +01:00
|
|
|
if !exists('*VimwikiLinkHandler')
|
2012-06-07 02:00:00 +02:00
|
|
|
function VimwikiLinkHandler(url)
|
|
|
|
return 0
|
2010-01-20 01:00:00 +01:00
|
|
|
endfunction
|
2018-04-20 07:03:53 +02:00
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if !exists('*VimwikiLinkConverter')
|
2015-04-29 14:59:10 +02:00
|
|
|
function VimwikiLinkConverter(url, source, target)
|
|
|
|
" Return the empty string when unable to process link
|
|
|
|
return ''
|
|
|
|
endfunction
|
2018-04-20 07:03:53 +02:00
|
|
|
endif
|
2015-04-29 14:59:10 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if !exists('*VimwikiWikiIncludeHandler')
|
2018-04-20 07:03:53 +02:00
|
|
|
function! VimwikiWikiIncludeHandler(value)
|
2012-06-07 02:00:00 +02:00
|
|
|
return ''
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
endif
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Write a level 1 header to new wiki files
|
2019-04-13 15:00:06 +02:00
|
|
|
" a:fname should be an absolute filepath
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:create_h1(fname) abort
|
2019-04-13 15:00:06 +02:00
|
|
|
if vimwiki#vars#get_global('auto_header')
|
|
|
|
let idx = vimwiki#vars#get_bufferlocal('wiki_nr')
|
|
|
|
|
|
|
|
" don't do anything for unregistered wikis
|
|
|
|
if idx == -1
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" don't create header for the diary index page
|
|
|
|
if vimwiki#path#is_equal(a:fname,
|
|
|
|
\ vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx).
|
|
|
|
\ vimwiki#vars#get_wikilocal('diary_index', idx).vimwiki#vars#get_wikilocal('ext', idx))
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" get tail of filename without extension
|
|
|
|
let title = expand('%:t:r')
|
|
|
|
|
|
|
|
" don't insert header for index page
|
|
|
|
if title ==# vimwiki#vars#get_wikilocal('index', idx)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" don't substitute space char for diary pages
|
|
|
|
if title !~# '^\d\{4}-\d\d-\d\d'
|
|
|
|
" NOTE: it is possible this could remove desired characters if the 'links_space_char'
|
|
|
|
" character matches characters that are intentionally used in the title.
|
|
|
|
let title = substitute(title, vimwiki#vars#get_wikilocal('links_space_char'), ' ', 'g')
|
|
|
|
endif
|
|
|
|
|
|
|
|
" insert the header
|
|
|
|
if vimwiki#vars#get_wikilocal('syntax') ==? 'markdown'
|
|
|
|
keepjumps call append(0, '# ' . title)
|
|
|
|
for _ in range(vimwiki#vars#get_global('markdown_header_style'))
|
|
|
|
keepjumps call append(1, '')
|
|
|
|
endfor
|
|
|
|
else
|
|
|
|
keepjumps call append(0, '= ' . title . ' =')
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
" Define autocommands for all known wiki extensions
|
2016-12-25 21:35:56 +01:00
|
|
|
let s:known_extensions = s:vimwiki_get_known_extensions()
|
|
|
|
|
|
|
|
if index(s:known_extensions, '.wiki') > -1
|
|
|
|
augroup filetypedetect
|
|
|
|
" clear FlexWiki's stuff
|
|
|
|
au! * *.wiki
|
|
|
|
augroup end
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
augroup vimwiki
|
|
|
|
autocmd!
|
2018-10-28 21:04:24 +01:00
|
|
|
autocmd ColorScheme * call s:setup_cleared_syntax()
|
2019-08-18 22:47:19 +02:00
|
|
|
|
|
|
|
" ['.md', '.mdown'] => *.md,*.mdown
|
|
|
|
let pat = join(map(s:known_extensions, '"*" . v:val'), ',')
|
|
|
|
exe 'autocmd BufNewFile,BufRead '.pat.' call s:setup_new_wiki_buffer()'
|
|
|
|
exe 'autocmd BufEnter '.pat.' call s:setup_buffer_enter()'
|
|
|
|
exe 'autocmd BufLeave '.pat.' call s:setup_buffer_leave()'
|
|
|
|
exe 'autocmd BufWinEnter '.pat.' call s:setup_buffer_win_enter()'
|
|
|
|
if exists('##DiffUpdated')
|
|
|
|
exe 'autocmd DiffUpdated '.pat.' call s:setup_buffer_win_enter()'
|
|
|
|
endif
|
|
|
|
" automatically generate a level 1 header for new files
|
|
|
|
exe 'autocmd BufNewFile '.pat.' call s:create_h1(expand("%:p"))'
|
|
|
|
" Format tables when exit from insert mode. Do not use textwidth to
|
|
|
|
" autowrap tables.
|
|
|
|
if vimwiki#vars#get_global('table_auto_fmt')
|
|
|
|
exe 'autocmd InsertLeave '.pat.' call vimwiki#tbl#format(line("."), 2)'
|
|
|
|
endif
|
|
|
|
if vimwiki#vars#get_global('folding') =~? ':quick$'
|
|
|
|
" from http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
|
|
|
|
" Don't screw up folds when inserting text that might affect them, until
|
|
|
|
" leaving insert mode. Foldmethod is local to the window. Protect against
|
|
|
|
" screwing up folding when switching between windows.
|
|
|
|
exe 'autocmd InsertEnter '.pat.' if !exists("w:last_fdm") | let w:last_fdm=&foldmethod'.
|
|
|
|
\ ' | setlocal foldmethod=manual | endif'
|
|
|
|
exe 'autocmd InsertLeave,WinLeave '.pat.' if exists("w:last_fdm") |'.
|
|
|
|
\ 'let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif'
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
augroup END
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Declare global commands
|
2011-06-11 02:00:00 +02:00
|
|
|
command! VimwikiUISelect call vimwiki#base#ui_select()
|
2019-03-31 03:12:56 +02:00
|
|
|
|
|
|
|
" these commands take a count e.g. :VimwikiIndex 2
|
|
|
|
" the default behavior is to open the index, diary etc.
|
|
|
|
" for the CURRENT wiki if no count is given
|
|
|
|
command! -count=0 VimwikiIndex
|
|
|
|
\ call vimwiki#base#goto_index(<count>)
|
|
|
|
|
|
|
|
command! -count=0 VimwikiTabIndex
|
|
|
|
\ call vimwiki#base#goto_index(<count>, 1)
|
|
|
|
|
|
|
|
command! -count=0 VimwikiDiaryIndex
|
|
|
|
\ call vimwiki#diary#goto_diary_index(<count>)
|
|
|
|
|
|
|
|
command! -count=0 VimwikiMakeDiaryNote
|
|
|
|
\ call vimwiki#diary#make_note(<count>)
|
|
|
|
|
|
|
|
command! -count=0 VimwikiTabMakeDiaryNote
|
|
|
|
\ call vimwiki#diary#make_note(<count>, 1)
|
|
|
|
|
|
|
|
command! -count=0 VimwikiMakeYesterdayDiaryNote
|
|
|
|
\ call vimwiki#diary#make_note(<count>, 0,
|
2020-07-21 19:21:43 +02:00
|
|
|
\ vimwiki#diary#diary_date_link(localtime(), -1))
|
2019-03-31 03:12:56 +02:00
|
|
|
|
|
|
|
command! -count=0 VimwikiMakeTomorrowDiaryNote
|
|
|
|
\ call vimwiki#diary#make_note(<count>, 0,
|
2020-07-21 19:21:43 +02:00
|
|
|
\ vimwiki#diary#diary_date_link(localtime(), 1))
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
command! VimwikiDiaryGenerateLinks
|
|
|
|
\ call vimwiki#diary#generate_diary_section()
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-06-12 20:55:56 +02:00
|
|
|
command! VimwikiShowVersion call s:get_version()
|
|
|
|
|
2016-12-25 21:35:56 +01:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Declare global maps
|
2019-04-27 05:17:35 +02:00
|
|
|
" <Plug> global definitions
|
|
|
|
nnoremap <silent><script> <Plug>VimwikiIndex
|
2019-08-25 22:25:31 +02:00
|
|
|
\ :<C-U>call vimwiki#base#goto_index(v:count)<CR>
|
2019-04-27 05:17:35 +02:00
|
|
|
nnoremap <silent><script> <Plug>VimwikiTabIndex
|
2019-08-25 22:25:31 +02:00
|
|
|
\ :<C-U>call vimwiki#base#goto_index(v:count, 1)<CR>
|
2019-04-27 05:17:35 +02:00
|
|
|
nnoremap <silent><script> <Plug>VimwikiUISelect
|
|
|
|
\ :VimwikiUISelect<CR>
|
|
|
|
nnoremap <silent><script> <Plug>VimwikiDiaryIndex
|
2019-03-31 03:12:56 +02:00
|
|
|
\ :<C-U>call vimwiki#diary#goto_diary_index(v:count)<CR>
|
2019-04-27 05:17:35 +02:00
|
|
|
nnoremap <silent><script> <Plug>VimwikiDiaryGenerateLinks
|
|
|
|
\ :VimwikiDiaryGenerateLinks<CR>
|
|
|
|
nnoremap <silent><script> <Plug>VimwikiMakeDiaryNote
|
2019-03-31 03:12:56 +02:00
|
|
|
\ :<C-U>call vimwiki#diary#make_note(v:count)<CR>
|
2019-04-27 05:17:35 +02:00
|
|
|
nnoremap <silent><script> <Plug>VimwikiTabMakeDiaryNote
|
2019-03-31 03:12:56 +02:00
|
|
|
\ :<C-U>call vimwiki#diary#make_note(v:count, 1)<CR>
|
2019-04-27 05:17:35 +02:00
|
|
|
nnoremap <silent><script> <Plug>VimwikiMakeYesterdayDiaryNote
|
2019-03-31 03:12:56 +02:00
|
|
|
\ :<C-U>call vimwiki#diary#make_note(v:count, 0,
|
2020-07-21 19:21:43 +02:00
|
|
|
\ vimwiki#diary#diary_date_link(localtime(), -1))<CR>
|
2019-04-27 05:17:35 +02:00
|
|
|
nnoremap <silent><script> <Plug>VimwikiMakeTomorrowDiaryNote
|
2019-03-31 03:12:56 +02:00
|
|
|
\ :<C-U>call vimwiki#diary#make_note(v:count, 0,
|
2020-07-21 19:21:43 +02:00
|
|
|
\ vimwiki#diary#diary_date_link(localtime(), 1))<CR>
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Get the user defined prefix (default <leader>w)
|
2019-04-27 05:17:35 +02:00
|
|
|
let s:map_prefix = vimwiki#vars#get_global('map_prefix')
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
|
|
|
|
" Set default global key mappings
|
2019-04-27 05:17:35 +02:00
|
|
|
if str2nr(vimwiki#vars#get_global('key_mappings').global)
|
2019-04-30 07:03:00 +02:00
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . 'w', '<Plug>VimwikiIndex', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . 't', '<Plug>VimwikiTabIndex', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . 's', '<Plug>VimwikiUISelect', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . 'i', '<Plug>VimwikiDiaryIndex', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>i', '<Plug>VimwikiDiaryGenerateLinks', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>w', '<Plug>VimwikiMakeDiaryNote', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>t', '<Plug>VimwikiTabMakeDiaryNote', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>y', '<Plug>VimwikiMakeYesterdayDiaryNote', 2)
|
|
|
|
call vimwiki#u#map_key('n', s:map_prefix . '<Leader>m', '<Plug>VimwikiMakeTomorrowDiaryNote', 2)
|
2019-04-27 05:17:35 +02:00
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Build global wiki menu (GUI)
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:build_menu(topmenu) abort
|
2019-04-21 21:05:01 +02:00
|
|
|
let wnamelist = []
|
2016-12-25 21:35:56 +01:00
|
|
|
for idx in range(vimwiki#vars#number_of_wikis())
|
2019-04-21 21:05:01 +02:00
|
|
|
let wname = vimwiki#vars#get_wikilocal('name', idx)
|
|
|
|
if wname ==? ''
|
|
|
|
" fall back to the path if wiki isn't named
|
|
|
|
let wname = fnamemodify(vimwiki#vars#get_wikilocal('path', idx), ':h:t')
|
|
|
|
endif
|
|
|
|
|
|
|
|
if index(wnamelist, wname) != -1
|
|
|
|
" append wiki index number to duplicate entries
|
|
|
|
let wname = wname . ' ' . string(idx + 1)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" add entry to the list of names for duplicate checks
|
|
|
|
call add(wnamelist, wname)
|
|
|
|
|
|
|
|
" escape spaces and periods
|
|
|
|
let wname = escape(wname, '\ \.')
|
|
|
|
|
|
|
|
" build the menu
|
|
|
|
execute 'menu '.a:topmenu.'.Open\ index.'.wname.
|
2018-05-17 21:47:50 +02:00
|
|
|
\ ' :call vimwiki#base#goto_index('.(idx+1).')<CR>'
|
2019-04-21 21:05:01 +02:00
|
|
|
execute 'menu '.a:topmenu.'.Open/Create\ diary\ note.'.wname.
|
2018-05-17 20:06:27 +02:00
|
|
|
\ ' :call vimwiki#diary#make_note('.(idx+1).')<CR>'
|
2016-12-25 21:35:56 +01:00
|
|
|
endfor
|
2010-01-20 01:00:00 +01:00
|
|
|
endfunction
|
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
|
|
|
|
" Build global table menu (GUI)
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:build_table_menu(topmenu) abort
|
2010-02-23 01:00:00 +01:00
|
|
|
exe 'menu '.a:topmenu.'.-Sep- :'
|
|
|
|
exe 'menu '.a:topmenu.'.Table.Create\ (enter\ cols\ rows) :VimwikiTable '
|
|
|
|
exe 'nmenu '.a:topmenu.'.Table.Format<tab>gqq gqq'
|
2010-05-12 02:00:00 +02:00
|
|
|
exe 'nmenu '.a:topmenu.'.Table.Move\ column\ left<tab><A-Left> :VimwikiTableMoveColumnLeft<CR>'
|
2018-04-20 07:03:53 +02:00
|
|
|
exe 'nmenu '.a:topmenu.
|
|
|
|
\ '.Table.Move\ column\ right<tab><A-Right> :VimwikiTableMoveColumnRight<CR>'
|
2010-02-23 01:00:00 +01:00
|
|
|
exe 'nmenu disable '.a:topmenu.'.Table'
|
|
|
|
endfunction
|
|
|
|
|
2016-12-21 19:43:34 +01:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Build Menus now
|
2016-12-21 21:28:48 +01:00
|
|
|
if !empty(vimwiki#vars#get_global('menu'))
|
|
|
|
call s:build_menu(vimwiki#vars#get_global('menu'))
|
|
|
|
call s:build_table_menu(vimwiki#vars#get_global('menu'))
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" Hook for calendar.vim
|
2016-12-21 21:28:48 +01:00
|
|
|
if vimwiki#vars#get_global('use_calendar')
|
2011-06-11 02:00:00 +02:00
|
|
|
let g:calendar_action = 'vimwiki#diary#calendar_action'
|
|
|
|
let g:calendar_sign = 'vimwiki#diary#calendar_sign'
|
2010-02-23 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-06-04 23:29:26 +02:00
|
|
|
" Restore peace in the galaxy
|
2019-12-21 04:41:03 +01:00
|
|
|
let &cpoptions = s:old_cpo
|