diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
index 97507ef..4356a3b 100644
--- a/autoload/vimwiki/base.vim
+++ b/autoload/vimwiki/base.vim
@@ -2918,23 +2918,59 @@ function! vimwiki#base#complete_colorize(ArgLead, CmdLine, CursorPos) abort
return join(colorlist, "\n")
endfunction
-function! vimwiki#base#colorize(...) abort
+function! vimwiki#base#get_user_color(...) abort
+ " Returns a color key <- user input, '' if fails
+ let res = ''
+ let display_list = []
+ let color_dic = vimwiki#vars#get_wikilocal('color_dic')
+ let key_list = sort(keys(color_dic))
+ let i = 1
+ for key in key_list
+ call add(display_list, string(i) . '. ' . key)
+ let i += 1
+ endfor
+ call insert(display_list, 'Select color:')
+ " Ask user, fails if 0
+ let i_selected = inputlist(display_list)
+ if i_selected != 0
+ let res = key_list[i_selected - 1]
+ endif
+ return res
+endfunction
+
+function! vimwiki#base#colorize(...) range abort
" TODO Must be coherent with color_tag_template
+ " Arg1: Key, list them with VimwikiColorize completion
+ " Arg2: visualmode()
" -- Just removeing spaces, \/ -> /, replacing COLORFG will do it
let key = a:0 ? a:1 : 'default'
+ let mode = a:0 > 1 ? a:2 : ''
let color_dic = vimwiki#vars#get_wikilocal('color_dic')
+ " Guard: if key = '', silently leave (user left inputlist)
+ if key ==# ''
+ return
+ endif
+
" Guard: color key nust exist
if !has_key(color_dic, key)
call vimwiki#u#error('color_dic variable has no key ''' . key . '''')
return
endif
- " Get content
- let content = getline('.')
- " TODO save position for visual selection: see u#get_selection
+ " Get content if called with a map with range
+ if mode !=# ''
+ " Visual mode
+ let firstline = getpos("'<")[1]
+ let lastline = getpos("'>")[1]
+ else
+ " Range command
+ let firstline = a:firstline
+ let lastline = a:lastline
+ endif
+ let lines = getline(firstline, lastline)
- " Surround
+ " Prepare
" -- pre
let [fg, bg] = color_dic[key]
let pre = ''
" -- post
let post = ''
- " -- concat
- let content = pre . content . post
+
+ " Concat
+ if mode !=# ''
+ " Visual mode (vim indexing ...)
+ let pos = getpos("'>")[2] - 1
+ let lines[len(lines)-1] = strpart(lines[len(lines)-1], 0, pos+1) . post . strpart(lines[len(lines)-1], pos+1)
+ let pos = getpos("'<")[2]
+ let lines[0] = strpart(lines[0],0, pos-1) . pre . strpart(lines[0], pos-1)
+ else
+ " Normal or Command
+ let lines[len(lines)-1] = lines[len(lines)-1] . post
+ let lines[0] = pre . lines[0]
+ endif
" Set buffer content
- call setline('.', content)
+ for line in range(firstline, lastline)
+ call setline(line, lines[line - firstline])
+ endfor
endfunction
" -------------------------------------------------------------------------
diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt
index 22c7ca2..ce749f0 100644
--- a/doc/vimwiki.txt
+++ b/doc/vimwiki.txt
@@ -381,6 +381,11 @@ MAP MODE
Maps to |:VimwikiPrevLink|.
Remap command: `VimwikiPrevLink`
+ *vimwiki_wc*
+wc n v Colorize line or selection if from visual mode
+ Maps to |:VimwikiColorize| after asking user for color
+ Remap command: `VimwikiColorize`
+
*vimwiki_wn*
wn n Goto or create new wiki page.
Maps to |:VimwikiGoto|.
@@ -965,13 +970,9 @@ Vimwiki file.
sure the tags have been built (see |vimwiki-build-tags|).
*:VimwikiColorize* red
- Colorize current line with the color given in argument. The possible
+ Colorize |range| of lines with the color given in argument. The possible
colors are configured by |vimwiki-option-color_dic| and the format of the
surrounding color tags by |vimwiki-option-color_tag_template|
- TODO
- Currently only the current line is colorized, a support for the selection
- will come. Maybe some mapping and color completion in popup (See
- changelog
==============================================================================
@@ -2867,7 +2868,7 @@ Default: 0
Dictionary containing the possible html colors for |:VimwikiColorize| the
keys are the color names used as argument, the values are a list [foreground,
-backgroud] of the color. For example:
+background] of the color. For example:
{'red': ['#cc241d', ''], 'bred': ['', '#cc241d']}
@@ -3902,6 +3903,7 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from
https://github.com/vimwiki-backup/vimwiki/issues.
New:~
+ * Feature: VimwikiColorize maps in visual and normal mode `wc`
* Feature: PR #686: add a flag lists_return to disable mappings
to and in insert mode
* Feature: enable re-mapping insert mode table mappings
diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim
index de585c9..d8af835 100644
--- a/ftplugin/vimwiki.vim
+++ b/ftplugin/vimwiki.vim
@@ -370,9 +370,8 @@ command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags
command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p'))
command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(expand('%:p'))
-
-command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_colorize
- \ VimwikiColorize call vimwiki#base#colorize()
+command! -buffer -nargs=* -range -complete=custom,vimwiki#base#complete_colorize
+ \ VimwikiColorize ,call vimwiki#base#colorize()
" ------------------------------------------------
" Keybindings
@@ -430,6 +429,10 @@ nnoremap