diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index d332d5d..fc2d839 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1287,19 +1287,23 @@ endfunction function! vimwiki#base#goto_index(wnum, ...) + + " if wnum = 0 the current wiki is used + if a:wnum == 0 + let idx = vimwiki#vars#get_bufferlocal('wiki_nr') + echom idx + if idx < 0 " not in a wiki + let idx = 0 + endif + else + let idx = a:wnum - 1 " convert to 0 based counting + endif + if a:wnum > vimwiki#vars#number_of_wikis() echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in your Vimwiki settings!' return endif - " usually a:wnum is greater then 0 but with the following command it is == 0: - " vim -n -c ":VimwikiIndex" - if a:wnum > 0 - let idx = a:wnum - 1 - else - let idx = 0 - endif - if a:0 if a:1 == 1 let cmd = 'tabedit' diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim index bfbbb82..6f9cd29 100644 --- a/autoload/vimwiki/diary.vim +++ b/autoload/vimwiki/diary.vim @@ -220,8 +220,6 @@ function! vimwiki#diary#make_note(wnum, ...) return endif - " TODO: refactor it. base#goto_index uses the same - call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr). \ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr)) @@ -244,20 +242,23 @@ function! vimwiki#diary#make_note(wnum, ...) call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr)) endfunction - function! vimwiki#diary#goto_diary_index(wnum) + + " if wnum = 0 the current wiki is used + if a:wnum == 0 + let idx = vimwiki#vars#get_bufferlocal('wiki_nr') + if idx < 0 " not in a wiki + let idx = 0 + endif + else + let idx = a:wnum - 1 " convert to 0 based counting + endif + if a:wnum > vimwiki#vars#number_of_wikis() echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!' return endif - " TODO: refactor it. base#goto_index uses the same - if a:wnum > 0 - let idx = a:wnum - 1 - else - let idx = 0 - endif - call vimwiki#base#edit_file('e', s:diary_index(idx), '') if vimwiki#vars#get_wikilocal('auto_diary_index') diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 2c95023..80abf2f 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -149,9 +149,9 @@ See also |:VimwikiUISelect| [count]wi or VimwikiDiaryIndex Open diary index file of the [count]'s wiki. - wi opens diary index file of the first wiki from + wi opens diary index file of the current wiki. + 1wi opens diary index file of the first wiki from |g:vimwiki_list|. - 1wi the same as above. 2wi opens diary index file of the second wiki from |g:vimwiki_list|. etc. @@ -164,10 +164,9 @@ See also |:VimwikiDiaryIndex| [count]ww or VimwikiMakeDiaryNote Open diary wiki-file for today of the [count]'s wiki. - ww opens diary wiki-file for today in the first wiki + ww opens diary wiki-file for today in the current wiki + 1ww opens diary wiki-file for today in the first wiki from |g:vimwiki_list|. - 1ww as above opens diary wiki-file for today in the - first wiki from |g:vimwiki_list|. 2ww opens diary wiki-file for today in the second wiki from |g:vimwiki_list|. 3ww opens diary wiki-file for today in the third wiki @@ -182,9 +181,9 @@ See also |:VimwikiMakeDiaryNote| [count]wt or VimwikiTabMakeDiaryNote Open diary wiki-file for today of the [count]'s wiki in a new tab. - wt tabopens diary wiki-file for today in the first - wiki from |g:vimwiki_list|. - 1wt as above tabopens diary wiki-file for today in the + wt tabopens diary wiki-file for today in the current + wiki + 1wt tabopens diary wiki-file for today in the first wiki from |g:vimwiki_list|. 2wt tabopens diary wiki-file for today in the second wiki from |g:vimwiki_list|. @@ -200,10 +199,10 @@ See also |:VimwikiTabMakeDiaryNote| [count]wy or VimwikiMakeYesterdayDiaryNote Open diary wiki-file for yesterday of the [count]'s wiki. - wy opens diary wiki-file for yesterday in the first + wy opens diary wiki-file for yesterday in the current + wiki + 1wy opens diary wiki-file for yesterday in the first wiki from |g:vimwiki_list|. - 1wy as above opens diary wiki-file for yesterday in - the first wiki from |g:vimwiki_list|. 2wy opens diary wiki-file for yesterday in the second wiki from |g:vimwiki_list|. 3wy opens diary wiki-file for yesterday in the third @@ -217,10 +216,10 @@ See also |:VimwikiMakeYesterdayDiaryNote| [count]wm or VimwikiMakeTomorrowDiaryNote Open diary wiki-file for tomorrow of the [count]'s wiki. - wm opens diary wiki-file for tomorrow in the first + wm opens diary wiki-file for tomorrow in the current + wiki + 1wm opens diary wiki-file for tomorrow in the first wiki from |g:vimwiki_list|. - 1wm as above opens diary wiki-file for tomorrow in - the first wiki from |g:vimwiki_list|. 2wm opens diary wiki-file for tomorrow in the second wiki from |g:vimwiki_list|. 3wm opens diary wiki-file for tomorrow in the third @@ -653,29 +652,41 @@ il A single list item. ------------------------------------------------------------------------------ 4.1. Global Commands *vimwiki-global-commands* -*:VimwikiIndex* - Open index file of the current wiki. +*:VimwikiIndex* [count] + Open index file of the current wiki. If a [count] is given the + corresponding wiki from |g:vimwiki_list| is opened instead. -*:VimwikiTabIndex* - Open index file of the current wiki in a new tab. +*:VimwikiTabIndex* [count] + Open index file of the current wiki in a new tab. If a [count] is given + the corresponding wiki from |g:vimwiki_list| is opened instead. *:VimwikiUISelect* - Open index file of the selected wiki. + Displays a list of registered wikis and opens the index file of the + selected wiki. -*:VimwikiDiaryIndex* - Open diary index file of the current wiki. +*:VimwikiDiaryIndex* [count] + Open diary index file of the current wiki. If a [count] is given the + corresponding wiki from |g:vimwiki_list| is opened instead. -*:VimwikiMakeDiaryNote* - Open diary wiki-file for today of the current wiki. +*:VimwikiMakeDiaryNote* [count] + Open diary wiki-file for today of the current wiki. If a [count] is given + a diary wiki-file for the corresponding wiki from |g:vimwiki_list| is + opened instead. -*:VimwikiTabMakeDiaryNote* - Open diary wiki-file for today of the current wiki in a new tab. +*:VimwikiTabMakeDiaryNote* [count] + Open diary wiki-file for today of the current wiki in a new tab. If + a [count] is given a diary wiki-file for the corresponding wiki from + |g:vimwiki_list| is opened instead. -*:VimwikiMakeYesterdayDiaryNote* - Open diary wiki-file for yesterday of the current wiki. +*:VimwikiMakeYesterdayDiaryNote* [count] + Open diary wiki-file for yesterday of the current wiki. If a [count] is + given a diary wiki-file for the corresponding wiki from |g:vimwiki_list| + is opened instead. -*:VimwikiMakeTomorrowDiaryNote* - Open diary wiki-file for tomorrow of the current wiki. +*:VimwikiMakeTomorrowDiaryNote* [count] + Open diary wiki-file for tomorrow of the current wiki. If a [count] is + given a diary wiki-file for the corresponding wiki from |g:vimwiki_list| + is opened instead. ------------------------------------------------------------------------------ 4.2. Local commands *vimwiki-local-commands* diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index 350a560..18c61f2 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -194,8 +194,7 @@ endfunction function! s:get_version() - if s:plugin_vers != -1 - echo "Stable version: " . s:plugin_vers + if s:plugin_vers != -1 echo "Stable version: " . s:plugin_vers else let a:plugin_rev = system("git --git-dir " . s:plugin_dir . "/.git rev-parse --short HEAD") let a:plugin_branch = system("git --git-dir " . s:plugin_dir . "/.git rev-parse --abbrev-ref HEAD") @@ -280,24 +279,31 @@ augroup END command! VimwikiUISelect call vimwiki#base#ui_select() -" why not using instead of v:count1? -" See https://github.com/vimwiki-backup/vimwiki/issues/324 -command! -count=1 VimwikiIndex - \ call vimwiki#base#goto_index(v:count1) -command! -count=1 VimwikiTabIndex - \ call vimwiki#base#goto_index(v:count1, 1) -command! -count=1 VimwikiDiaryIndex - \ call vimwiki#diary#goto_diary_index(v:count1) -command! -count=1 VimwikiMakeDiaryNote - \ call vimwiki#diary#make_note(v:count) -command! -count=1 VimwikiTabMakeDiaryNote - \ call vimwiki#diary#make_note(v:count, 1) -command! -count=1 VimwikiMakeYesterdayDiaryNote - \ call vimwiki#diary#make_note(v:count, 0, +" 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() + +command! -count=0 VimwikiTabIndex + \ call vimwiki#base#goto_index(, 1) + +command! -count=0 VimwikiDiaryIndex + \ call vimwiki#diary#goto_diary_index() + +command! -count=0 VimwikiMakeDiaryNote + \ call vimwiki#diary#make_note() + +command! -count=0 VimwikiTabMakeDiaryNote + \ call vimwiki#diary#make_note(, 1) + +command! -count=0 VimwikiMakeYesterdayDiaryNote + \ call vimwiki#diary#make_note(, 0, \ vimwiki#diary#diary_date_link(localtime() - 60*60*24)) -command! -count=1 VimwikiMakeTomorrowDiaryNote - \ call vimwiki#diary#make_note(v:count, 0, + +command! -count=0 VimwikiMakeTomorrowDiaryNote + \ call vimwiki#diary#make_note(, 0, \ vimwiki#diary#diary_date_link(localtime() + 60*60*24)) command! VimwikiDiaryGenerateLinks @@ -305,19 +311,19 @@ command! VimwikiDiaryGenerateLinks command! VimwikiShowVersion call s:get_version() - - let s:map_prefix = vimwiki#vars#get_global('map_prefix') if !hasmapto('VimwikiIndex') && maparg(s:map_prefix.'w', 'n') == "" exe 'nmap '.s:map_prefix.'w VimwikiIndex' endif -nnoremap