diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 2b0d1e6..f41264f 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -560,8 +560,8 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{ endif endfunction " }}} -" vimwiki#base#generate_links -function! vimwiki#base#generate_links() "{{{only get links from the current dir +" vimwiki#base#get_globlinks_escaped +function! vimwiki#base#get_globlinks_escaped() abort "{{{only get links from the current dir " change to the directory of the current file let orig_pwd = getcwd() lcd! %:h @@ -571,6 +571,19 @@ function! vimwiki#base#generate_links() "{{{only get links from the current dir let globlinks = substitute(globlinks, '\'.VimwikiGet('ext').'\ze\n', '', 'g') " restore the original working directory exe 'lcd! '.orig_pwd + " convert to a List + let lst = split(globlinks, '\n') + " Apply fnameescape() to each item + call map(lst, 'fnameescape(v:val)') + " Convert back to newline-separated list + let globlinks = join(lst, "\n") + " return all escaped links as a single newline-separated string + return globlinks +endfunction " }}} + +" vimwiki#base#generate_links +function! vimwiki#base#generate_links() "{{{only get links from the current dir + let globlinks = vimwiki#base#get_globlinks() " We don't want link to itself. XXX Why ??? " let cur_link = expand('%:t:r') @@ -1837,6 +1850,17 @@ endfunction "}}} " }}} +" Command completion functions {{{ + +" vimwiki#base#complete_links_escaped +function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort " {{{ + " We can safely ignore args if we use -custom=complete option, Vim engine + " will do the job of filtering. + return vimwiki#base#get_globlinks_escaped() +endfunction " }}} + +"}}} + " ------------------------------------------------------------------------- " Load syntax-specific Wiki functionality for s:syn in vimwiki#base#get_known_syntaxes() diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index a486849..292043a 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -597,6 +597,8 @@ il A single list item. :VimwikiGoto HelloWorld < opens opens/creates HelloWorld wiki page. + Supports |cmdline-completion| for link name. + *:VimwikiDeleteLink* Delete the wiki page that you are in. diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 90d26db..1c9fbd0 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -283,7 +283,8 @@ exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep '. exe 'command! -buffer -nargs=* VWS lvimgrep '. \ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') -command! -buffer -nargs=+ VimwikiGoto call vimwiki#base#goto() +command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links_escaped + \ VimwikiGoto call vimwiki#base#goto() " list commands