@@ -34,6 +34,18 @@ if !exists('g:bullets_mapping_leader')
3434 let g: bullets_mapping_leader = ' '
3535end
3636
37+ " Extra key mappings in addition to default ones.
38+ " If you don’t need default mappings set 'g:bullets_set_mappings' to '0'.
39+ " N.B. 'g:bullets_mapping_leader' has no effect on these mappings.
40+ "
41+ " Example:
42+ " let g:bullets_custom_mappings = [
43+ " \ ['imap', '<cr>', '<Plug>(bullets-newline)'],
44+ " \ ]
45+ if ! exists (' g:bullets_custom_mappings' )
46+ let g: bullets_custom_mappings = []
47+ endif
48+
3749if ! exists (' g:bullets_delete_last_bullet_if_empty' )
3850 let g: bullets_delete_last_bullet_if_empty = 1
3951end
@@ -100,7 +112,7 @@ endif
100112
101113" Parse Bullet Type ------------------------------------------- {{{
102114fun ! s: parse_bullet (line_num, line_text)
103-
115+
104116 let l: bullet = s: match_bullet_list_item (a: line_text )
105117 " Must be a bullet to be a checkbox
106118 let l: check = ! empty (l: bullet ) ? s: match_checkbox_bullet_item (a: line_text ) : {}
@@ -966,14 +978,34 @@ command! -range=% BulletPromoteVisual call <SID>visual_change_bullet_level(1)
966978" --------------------------------------------------------- }}}
967979
968980" Keyboard mappings --------------------------------------- {{{
969- fun ! s: add_local_mapping (mapping_type, mapping , action)
981+
982+ " Automatic bullets
983+ inoremap <silent> <Plug> (bullets-newline) <C-]><C-R> =<SID> insert_new_bullet()<cr>
984+ nnoremap <silent> <Plug> (bullets-newline) :call <SID> insert_new_bullet()<cr>
985+
986+ " Renumber bullet list
987+ vnoremap <silent> <Plug> (bullets-renumber) :RenumberSelection<cr>
988+ nnoremap <silent> <Plug> (bullets-renumber) :RenumberList<cr>
989+
990+ " Toggle checkbox
991+ nnoremap <silent> <Plug> (bullets-toggle-checkbox) :ToggleCheckbox<cr>
992+
993+ " Promote and Demote outline level
994+ inoremap <silent> <Plug> (bullets-demote) <C-o> :BulletDemote<cr>
995+ nnoremap <silent> <Plug> (bullets-demote) :BulletDemote<cr>
996+ vnoremap <silent> <Plug> (bullets-demote) :BulletDemoteVisual<cr>
997+ inoremap <silent> <Plug> (bullets-promote) <C-o> :BulletPromote<cr>
998+ nnoremap <silent> <Plug> (bullets-promote) :BulletPromote<cr>
999+ vnoremap <silent> <Plug> (bullets-promote) :BulletPromoteVisual<cr>
1000+
1001+ fun ! s: add_local_mapping (with_leader, mapping_type, mapping , action)
9701002 let l: file_types = join (g: bullets_enabled_file_types , ' ,' )
9711003 execute ' autocmd FileType ' .
9721004 \ l: file_types .
9731005 \ ' ' .
9741006 \ a: mapping_type .
9751007 \ ' <silent> <buffer> ' .
976- \ g: bullets_mapping_leader .
1008+ \ ( a: with_leader ? g: bullets_mapping_leader : ' ' ) .
9771009 \ a: mapping .
9781010 \ ' ' .
9791011 \ a: action
@@ -982,7 +1014,7 @@ fun! s:add_local_mapping(mapping_type, mapping, action)
9821014 execute ' autocmd BufEnter * if bufname("") == "" | ' .
9831015 \ a: mapping_type .
9841016 \ ' <silent> <buffer> ' .
985- \ g: bullets_mapping_leader .
1017+ \ ( a: with_leader ? g: bullets_mapping_leader : ' ' ) .
9861018 \ a: mapping .
9871019 \ ' ' .
9881020 \ a: action .
@@ -994,27 +1026,31 @@ augroup TextBulletsMappings
9941026 autocmd !
9951027
9961028 if g: bullets_set_mappings
997- " automatic bullets
998- call s: add_local_mapping (' inoremap ' , ' <cr>' , ' <C-]><C-R>=<SID>insert_new_bullet()<cr> ' )
999- call s: add_local_mapping (' inoremap' , ' <C-cr>' , ' <cr>' )
1029+ " Automatic bullets
1030+ call s: add_local_mapping (1 , ' imap ' , ' <cr>' , ' <Plug>(bullets-newline) ' )
1031+ call s: add_local_mapping (1 , ' inoremap' , ' <C-cr>' , ' <cr>' )
10001032
1001- call s: add_local_mapping (' nnoremap ' , ' o' , ' :call <SID>insert_new_bullet()<cr> ' )
1033+ call s: add_local_mapping (1 , ' nmap ' , ' o' , ' <Plug>(bullets-newline) ' )
10021034
10031035 " Renumber bullet list
1004- call s: add_local_mapping (' vnoremap ' , ' gN' , ' :RenumberSelection<cr> ' )
1005- call s: add_local_mapping (' nnoremap ' , ' gN' , ' :RenumberList<cr> ' )
1036+ call s: add_local_mapping (1 , ' vmap ' , ' gN' , ' <Plug>(bullets-renumber) ' )
1037+ call s: add_local_mapping (1 , ' nmap ' , ' gN' , ' <Plug>(bullets-renumber) ' )
10061038
10071039 " Toggle checkbox
1008- call s: add_local_mapping (' nnoremap ' , ' <leader>x' , ' :ToggleCheckbox<cr> ' )
1040+ call s: add_local_mapping (1 , ' nmap ' , ' <leader>x' , ' <Plug>(bullets-toggle-checkbox) ' )
10091041
10101042 " Promote and Demote outline level
1011- call s: add_local_mapping (' inoremap ' , ' <C-t>' , ' <C-o>:BulletDemote<cr> ' )
1012- call s: add_local_mapping (' nnoremap ' , ' >>' , ' :BulletDemote<cr> ' )
1013- call s: add_local_mapping (' inoremap ' , ' <C-d >' , ' <C-o>:BulletPromote<cr> ' )
1014- call s: add_local_mapping (' nnoremap ' , ' << ' , ' :BulletPromote<cr> ' )
1015- call s: add_local_mapping (' vnoremap ' , ' > ' , ' :BulletDemoteVisual<cr> ' )
1016- call s: add_local_mapping (' vnoremap ' , ' <' , ' :BulletPromoteVisual<cr> ' )
1043+ call s: add_local_mapping (1 , ' imap ' , ' <C-t>' , ' <Plug>(bullets-demote) ' )
1044+ call s: add_local_mapping (1 , ' nmap ' , ' >>' , ' <Plug>(bullets-demote) ' )
1045+ call s: add_local_mapping (1 , ' vmap ' , ' >' , ' <Plug>(bullets-demote) ' )
1046+ call s: add_local_mapping (1 , ' imap ' , ' <C-d> ' , ' <Plug>(bullets-promote) ' )
1047+ call s: add_local_mapping (1 , ' nmap ' , ' << ' , ' <Plug>(bullets-promote) ' )
1048+ call s: add_local_mapping (1 , ' vmap ' , ' <' , ' <Plug>(bullets-promote) ' )
10171049 end
1050+
1051+ for s: custom_key_mapping in g: bullets_custom_mappings
1052+ call call (' <SID>add_local_mapping' , [0 ] + s: custom_key_mapping )
1053+ endfor
10181054augroup END
10191055" --------------------------------------------------------- }}}
10201056
0 commit comments