From 41aa647abafa09e03e6f136429fad0346c14b14a Mon Sep 17 00:00:00 2001 From: Rane Brown Date: Sun, 31 Mar 2019 21:16:44 -0600 Subject: [PATCH] Add option to set a character which replaces spaces when creating links. The wikilocal option links_space_char will be used to replace any spaces when creating a new wiki link and page. This only affects link creation with a visual selection. --- autoload/vimwiki/base.vim | 3 ++- autoload/vimwiki/markdown_base.vim | 3 ++- autoload/vimwiki/vars.vim | 1 + doc/vimwiki.txt | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index fc2d839..14d77a0 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -2134,7 +2134,8 @@ function! s:normalize_link_syntax_v() endif " Put substitution in register " and change text - call setreg('"', substitute(sub, '\n', '', ''), visualmode()) + let sc = vimwiki#vars#get_wikilocal('links_space_char') + call setreg('"', substitute(substitute(sub, '\n', '', ''), '\s', sc, 'g'), visualmode()) normal! `>""pgvd finally call setreg('"', default_register_save, registertype_save) diff --git a/autoload/vimwiki/markdown_base.vim b/autoload/vimwiki/markdown_base.vim index f1ce091..35de134 100644 --- a/autoload/vimwiki/markdown_base.vim +++ b/autoload/vimwiki/markdown_base.vim @@ -122,7 +122,8 @@ function! s:normalize_link_syntax_v() \ '__LinkUrl__', visual_selection, '') let link = s:safesubstitute(link, '__LinkDescription__', visual_selection, '') - call setreg('"', substitute(link, '\n', '', ''), visualmode()) + let sc = vimwiki#vars#get_wikilocal('links_space_char') + call setreg('"', substitute(substitute(link, '\n', '', ''), '\s', sc, 'g'), visualmode()) " paste result norm! `>""pgvd diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim index f04db38..ca12974 100644 --- a/autoload/vimwiki/vars.vim +++ b/autoload/vimwiki/vars.vim @@ -269,6 +269,7 @@ function! s:populate_wikilocal_options() \ 'exclude_files': {'type': type([]), 'default': []}, \ 'ext': {'type': type(''), 'default': '.wiki', 'min_length': 1}, \ 'index': {'type': type(''), 'default': 'index', 'min_length': 1}, + \ 'links_space_char': {'type': type(''), 'default': ' ', 'min_length': 1}, \ 'list_margin': {'type': type(0), 'default': -1, 'min': -1}, \ 'maxhi': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, \ 'nested_syntaxes': {'type': type({}), 'default': {}}, diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 80abf2f..a2d697f 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -2055,6 +2055,21 @@ converted to HTML at the moment. To use Markdown's wiki markup: > let g:vimwiki_list = [{'path': '~/my_site/', \ 'syntax': 'markdown', 'ext': '.md'}] + +*vimwiki-option-links_space_char* +------------------------------------------------------------------------------ +Key Default value~ +links_space_char ' ' + +Description~ +Set the character (or string) used to replace spaces when creating a link. For +example, setting '_' would transform the string 'my link' into [[my_link]] and +the created file would be my_link.wiki. The default behavior does not replace +spaces. + +To set the space replacement character: > + let g:vimwiki_list = [{'path': '~/my_site/', + \ 'links_space_char': '_'}] < *vimwiki-option-template_path*