diff --git a/autoload/vimwiki/u.vim b/autoload/vimwiki/u.vim index c8f62ee..f6adc4e 100644 --- a/autoload/vimwiki/u.vim +++ b/autoload/vimwiki/u.vim @@ -70,3 +70,22 @@ else endfunc endif +" a:mode single character indicating the mode as defined by :h maparg +" a:key the key sequence to map +" a:plug the plug command the key sequence should be mapped to +" a:1 optional argument to override the uniqueness checks +" this can be used to map different keys to the same definition +" This function maps a key sequence to a command using the arguments +" described above. If there is already a mapping to the command or +" the assigned keys are already mapped then nothing is done. +function vimwiki#u#map_key(mode, key, plug, ...) + if a:0 > 0 && a:1 == 1 + if maparg(a:key, a:mode) ==# '' + exe a:mode . 'map ' . a:key . ' ' . a:plug + endif + else + if !hasmapto(a:plug) && maparg(a:key, a:mode) ==# '' + exe a:mode . 'map ' . a:key . ' ' . a:plug + endif + endif +endfunction diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim index 5e0aaed..5cf9295 100644 --- a/autoload/vimwiki/vars.vim +++ b/autoload/vimwiki/vars.vim @@ -166,6 +166,12 @@ function! s:read_global_settings_from_user() \ 'hl_headers': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, \ 'html_header_numbering': {'type': type(0), 'default': 0, 'min': 0, 'max': 6}, \ 'html_header_numbering_sym': {'type': type(''), 'default': ''}, + \ 'key_mappings': {'type': type({}), 'default': + \ { + \ 'all_maps': 1, 'global': 1, 'headers': 1, 'text_objs': 1, + \ 'table_format': 1, 'table_mappings': 1, 'lists': 1, 'links': 1, + \ 'html': 1, 'mouse': 0, + \ }}, \ 'list_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, \ 'text_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, \ 'links_header': {'type': type(''), 'default': 'Generated Links', 'min_length': 1}, @@ -250,6 +256,64 @@ function! s:normalize_global_settings() let g:vimwiki_global_vars.ext2syntax[ext] = 'media' endif endfor + + " ensure key_mappings dictionary has all required keys + if !has_key(g:vimwiki_global_vars.key_mappings, 'all_maps') + let g:vimwiki_global_vars.key_mappings.all_maps = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'global') + let g:vimwiki_global_vars.key_mappings.global = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'headers') + let g:vimwiki_global_vars.key_mappings.headers = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'text_objs') + let g:vimwiki_global_vars.key_mappings.text_objs = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'table_format') + let g:vimwiki_global_vars.key_mappings.table_format = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'table_mappings') + let g:vimwiki_global_vars.key_mappings.table_mappings = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'lists') + let g:vimwiki_global_vars.key_mappings.lists = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'links') + let g:vimwiki_global_vars.key_mappings.links = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'html') + let g:vimwiki_global_vars.key_mappings.html = 1 + endif + if !has_key(g:vimwiki_global_vars.key_mappings, 'mouse') + let g:vimwiki_global_vars.key_mappings.mouse = 0 + endif + + " disable all key mappings if all_maps == 0 + if !g:vimwiki_global_vars.key_mappings.all_maps + let g:vimwiki_global_vars.key_mappings.global = 0 + let g:vimwiki_global_vars.key_mappings.headers = 0 + let g:vimwiki_global_vars.key_mappings.text_objs = 0 + let g:vimwiki_global_vars.key_mappings.table_format = 0 + let g:vimwiki_global_vars.key_mappings.table_mappings = 0 + let g:vimwiki_global_vars.table_mappings = 0 " kept for backwards compatibility + let g:vimwiki_global_vars.key_mappings.lists = 0 + let g:vimwiki_global_vars.key_mappings.links = 0 + let g:vimwiki_global_vars.key_mappings.html = 0 + let g:vimwiki_global_vars.key_mappings.mouse = 0 + let g:vimwiki_global_vars.use_mouse = 0 " kept for backwards compatibility + endif + + " TODO remove these checks and the table_mappings and use_mouse variables + " backwards compatibility checks + " if the old option isn't its default value then overwrite the new option + if g:vimwiki_global_vars.table_mappings == 0 + let g:vimwiki_global_vars.key_mappings.table_mappings = 0 && g:vimwiki_global_vars.key_mappings.table_mappings == 1 + endif + if g:vimwiki_global_vars.use_mouse == 1 && g:vimwiki_global_vars.key_mappings.mouse == 0 + let g:vimwiki_global_vars.key_mappings.mouse = 1 + endif + endfunction diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 8e6d359..995f81a 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -110,6 +110,10 @@ There are global and local mappings in Vimwiki. ------------------------------------------------------------------------------ 3.1. Global mappings *vimwiki-global-mappings* +NOTE: if a user mapping or mapping from another plugin uses the same key +sequence as one of the following mappings then Vimwiki will not overwrite it. + + [count]ww or VimwikiIndex Open index file of the [count]'s wiki. @@ -247,6 +251,9 @@ don't want that, use > :nmap tt VimwikiToggleListItem :vmap tt VimwikiToggleListItem +NOTE: if a user mapping or mapping from another plugin uses the same key +sequence as one of the following mappings then Vimwiki will not overwrite it. + NORMAL MODE *vimwiki-local-mappings* *vimwiki_wh* @@ -316,12 +323,6 @@ NORMAL MODE *vimwiki-local-mappings* Maps to |:VimwikiPrevLink|. To remap: > :nmap wp VimwikiPrevLink -< -gnt *vimwiki_gnt* - Find next unfinished task in the current page. - Maps to |:VimwikiNextTask| - To remap: > - :nmap nt VimwikiNextTask < *vimwiki_wd* wd Delete wiki page you are in. @@ -393,6 +394,12 @@ gnt *vimwiki_gnt* See |vimwiki-todo-lists|. To remap: > :map tt VimwikiToggleListItem + +gnt *vimwiki_gnt* + Find next unfinished task in the current page. + Maps to |:VimwikiNextTask| + To remap: > + :nmap nt VimwikiNextTask < *vimwiki_gl* *vimwiki_gL* gl Remove checkbox from list item. @@ -517,13 +524,19 @@ glx Toggle checkbox of a list item disabled/off. gqq Format table. If you made some changes to a table or without swapping insert/normal modes this command gww will reformat it. - + To remap: > + :nmap gq VimwikiTableAlignQ + :nmap gw VimwikiTableAlignW +< *vimwiki_gq1* *vimwiki_gw1* gq1 Fast format table. The same as the previous, except or that only a few lines above the current line are gw1 tested. If the alignment of the current line differs, then the whole table gets reformatted. - + To remap: > + :nmap q1 VimwikiTableAlignQ1 + :nmap w1 VimwikiTableAlignW1 +< *vimwiki_* Move current table column to the left. See |:VimwikiTableMoveColumnLeft| @@ -548,8 +561,11 @@ gw1 tested. If the alignment of the current line differs, To remap: > :nmap j VimwikiDiaryNextDay < +Mouse mappings *vimwiki_mouse* + +These mappings are disabled by default. +See |g:vimwiki_key_mappings| to enable. -Works only if |g:vimwiki_use_mouse| is set to 1. <2-LeftMouse> Follow wiki link (create target wiki page if needed). Split and follow wiki link (create target wiki page if @@ -572,7 +588,6 @@ INSERT MODE *vimwiki-table-mappings* *vimwiki_i__table* Go to the next table cell, create a new row if on the last cell. -See |g:vimwiki_table_mappings| to turn them off. INSERT MODE *vimwiki-list-mappings* *vimwiki_i_* @@ -645,6 +660,29 @@ ic An inner column in a table. al A list item plus its children. il A single list item. +These key mappings can be modified by replacing the default keys: > + + omap ah VimwikiTextObjHeader + vmap ah VimwikiTextObjHeaderV + omap ih VimwikiTextObjHeaderContent + vmap ih VimwikiTextObjHeaderContentV + omap aH VimwikiTextObjHeaderSub + vmap aH VimwikiTextObjHeaderSubV + omap iH VimwikiTextObjHeaderSubContent + vmap iH VimwikiTextObjHeaderSubContentV + omap a\ VimwikiTextObjTableCell + vmap a\ VimwikiTextObjTableCellV + omap i\ VimwikiTextObjTableCellInner + vmap i\ VimwikiTextObjTableCellInnerV + omap ac VimwikiTextObjColumn + vmap ac VimwikiTextObjColumnV + omap ic VimwikiTextObjColumnInner + vmap ic VimwikiTextObjColumnInnerV + omap al VimwikiTextObjListChildren + vmap al VimwikiTextObjListChildrenV + omap il VimwikiTextObjListSingle + vmap il VimwikiTextObjListSingleV + ============================================================================== 4. Commands *vimwiki-commands* @@ -1535,9 +1573,13 @@ Note that the mapping is not available in all terminals. Furthermore, and behave differently when the cursor is behind an empty list item. See the table below. -You can configure the behavior of and of like this: > - inoremap :VimwikiReturn 1 5 - inoremap :VimwikiReturn 2 2 +To remap the default behavior: > + :imap e VimwikiReturn15 + :imap r VimwikiReturn22 + +To customize the behavior: > + inoremap :VimwikiReturn 1 1 + inoremap :VimwikiReturn 3 5 The first argument of the command :VimwikiReturn is a number that specifies when to insert a new bullet/number and when not, depending on whether the @@ -2609,18 +2651,6 @@ You can set it to a more fancy symbol like this: let g:vimwiki_listsym_rejected = '✗' ------------------------------------------------------------------------------- -*g:vimwiki_use_mouse* - -Use local mouse mappings from |vimwiki-local-mappings|. - -Value Description~ -0 Do not use mouse mappings. -1 Use mouse mappings. - -Default: 0 - - ------------------------------------------------------------------------------ *g:vimwiki_folding* @@ -2819,18 +2849,6 @@ cannot otherwise convert the link. A customized handler might look like this: > endfunction < ------------------------------------------------------------------------------- -*g:vimwiki_table_mappings* - -Enable/disable table mappings for INSERT mode. - -Value Description~ -0 Disable table mappings. -1 Enable table mappings. - -Default: 1 - - ------------------------------------------------------------------------------ *g:vimwiki_table_auto_fmt* @@ -3231,6 +3249,77 @@ For example, with `links_space_char` set to `'_'` creating a link from the text The default is 0. +------------------------------------------------------------------------------ +*g:vimwiki_key_mappings* + +A dictionary that is used to enable/disable various key mapping groups. To +disable a specific group set the value for the associated key to 0. +For example: > + + let g:vimwiki_key_mappings = + \ { + \ 'headers': 0, + \ 'text_objs': 0, + \ } + +To disable ALL Vimwiki key mappings use: > + + let g:vimwiki_key_mappings = { 'all_maps': 0, } + +The valid key groups and their associated mappings are shown below. + +`all_maps`: + Used to disable all Vimwiki key mappings. +`global`: + |vimwiki-global-mappings| that are defined when Vim starts. +`headers`: + Mappings for header navigation and manipulation: + |vimwiki_=|, |vimwiki_-|, |vimwiki_[[|, |vimwiki_]]|, |vimwiki_[=| + |vimwiki_]=|, |vimwiki_]u| , |vimwiki_[u| +`text_objs`: + |vimwiki-text-objects| mappings. +`table_format`: + Mappings used for table formatting. + |vimwiki_gqq|, |vimwiki_gww|, |vimwiki_gq1|, |vimwiki_gw1| + |vimwiki_|, |vimwiki_| +`table_mappings`: + Table mappings for insert mode. + |vimwiki_|, |vimwiki_| +`lists`: + Mappings for list manipulation. + |vimwiki_|, |vimwiki_gl|, |vimwiki_gL| |vimwiki_gln|, |vimwiki_glp| + |vimwiki_gll|, |vimwiki_gLl|, |vimwiki_glh|, |vimwiki_gLh|, |vimwiki_glr|, |vimwiki_gLr| + |vimwiki_glsar|, |vimwiki_gLstar|, |vimwiki_gl#|, |vimwiki_gL#|, |vimwiki_gl-|, |vimwiki_gL-| + |vimwiki_gl1|, |vimwiki_gL1|, |vimwiki_gla|, |vimwiki_gLa|, |vimwiki_glA|, |vimwiki_gLA| + |vimwiki_gli|, |vimwiki_gLi|, |vimwiki_glI|, |vimwiki_gLI|, |vimwiki_glx| +`links`: + Mappings for link creation and navigation. + |vimwiki_wi|, |vimwiki_|, |vimwiki_|, |vimwiki_| + |vimwiki_|, |vimwiki_|, |vimwiki_|, |vimwiki_| + |vimwiki_|, |vimwiki_wd|, |vimwiki_wr|, |vimwiki_| + |vimwiki_|, |vimwiki_+|, |vimwiki_| +`html`: + Mappings for HTML generation. + |vimwiki_wh|, |vimwiki_whh| +`mouse`: + Mouse mappings, see |vimwiki_mouse|. This option is disabled by default. + +The default is to enable all key mappings except the mouse: > + let g:vimwiki_key_mappings = + \ { + \ 'all_maps': 1, + \ 'global': 1, + \ 'headers': 1, + \ 'text_objs': 1, + \ 'table_format': 1, + \ 'table_mappings': 1, + \ 'lists': 1, + \ 'links': 1, + \ 'html': 1, + \ 'mouse': 0, + \ } + + ============================================================================== 13. Getting help *vimwiki-help* @@ -3333,6 +3422,9 @@ New:~ * PR #683: Improve layout and format of key binding documentation in README and include note about key bindings that may not work. * PR #681: Prevent sticky type checking errors for old vim versions. + * PR #686: New option |g:vimwiki_key_mappings| that allow key mappings to + be enabled/disabled by groups. Key mappings are also no longer + overwritten if they are already defined. * PR #675: Add option |vimwiki-option-name| to assign a per wiki name. * PR #661: Add option |g:vimwiki_auto_header| to automatically generate a level 1 header for new wiki pages. @@ -3381,7 +3473,10 @@ New:~ * PR #47: Optimize table formatting for large tables. Removed:~ - * + * Options g:vimwiki_use_mouse and g:vimwiki_table_mappings. These are + still present in the code for backwards compatibility but have been + removed from the documentation and will be fully removed at a later + point. Fixed:~ * Issue #612: GVim menu displayed duplicate names. diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 02904a8..d7f456f 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -129,20 +129,6 @@ setlocal formatoptions+=n let &formatlistpat = vimwiki#vars#get_syntaxlocal('rxListItem') -if !empty(&langmap) - " Valid only if langmap is a comma separated pairs of chars - let s:l_o = matchstr(&langmap, '\C,\zs.\zeo,') - if s:l_o - exe 'nnoremap '.s:l_o.' :call vimwiki#lst#kbd_o()a' - endif - - let s:l_O = matchstr(&langmap, '\C,\zs.\zeO,') - if s:l_O - exe 'nnoremap '.s:l_O.' :call vimwiki#lst#kbd_O()a' - endif -endif - - " ------------------------------------------------ " Folding stuff @@ -330,7 +316,8 @@ command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(expand('%:p')) " Keybindings " ------------------------------------------------ -if vimwiki#vars#get_global('use_mouse') +" mouse mappings +if str2nr(vimwiki#vars#get_global('key_mappings').mouse) nmap nmap nnoremap <2-LeftMouse> @@ -340,224 +327,193 @@ if vimwiki#vars#get_global('use_mouse') nnoremap :VimwikiGoBackLink endif - -if !hasmapto('Vimwiki2HTML') - exe 'nmap '.vimwiki#vars#get_global('map_prefix').'h Vimwiki2HTML' -endif +" HTML definitions nnoremap