commit 41aa647abafa09e03e6f136429fad0346c14b14a
parent 3396e87dbee617cbf0aa5b6ee9bcfe21270cc19a
Author: Rane Brown <rane.brown@gmail.com>
Date: Sun, 31 Mar 2019 21:16:44 -0600
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.
Diffstat:
4 files changed, 20 insertions(+), 2 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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*