Skip to content

Commit 643a3c7

Browse files
feat: add <plug> mappings
* Add “<Plug>…” key maps * Add support for “g:bullets_custom_mappings” option * README: Add usage example for “g:bullets_custom_mappings” option * README: Add clarification comment for g:bullets_custom_mappings option Co-authored-by: Viacheslav Lotsmanov <[email protected]>
1 parent 770a93c commit 643a3c7

File tree

2 files changed

+89
-23
lines changed

2 files changed

+89
-23
lines changed

README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Bullets.vim](img/bullets-vim-logo.svg)
22

3-
[![Build Status](https://travis-ci.org/dkarter/bullets.vim.svg?branch=master)](https://travis-ci.org/dkarter/bullets.vim)
3+
[![Build Status](https://travis-ci.org/dkarter/bullets.vim.svg?branch=master)](https://travis-ci.org/dkarter/bullets.vim)
44

55
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
66
[![All Contributors](https://img.shields.io/badge/all_contributors-15-orange.svg?style=flat-square)](#contributors-)
@@ -79,6 +79,36 @@ Add a leader key before default mappings:
7979
let g:bullets_mapping_leader = '<M-b>' " default = ''
8080
```
8181

82+
Customize key mappings:
83+
84+
```vim
85+
let g:bullets_set_mappings = 0 " disable adding default key mappings, default = 1
86+
87+
" default = []
88+
" N.B. You can set these mappings as-is without using this g:bullets_custom_mappings option but it
89+
" will apply in this case for all file types while when using g:bullets_custom_mappings it would
90+
" take into account file types filter set in g:bullets_enabled_file_types, and also
91+
" g:bullets_enable_in_empty_buffers option.
92+
let g:bullets_custom_mappings = [
93+
\ ['imap', '<cr>', '<Plug>(bullets-newline)'],
94+
\ ['inoremap', '<C-cr>', '<cr>'],
95+
\
96+
\ ['nmap', 'o', '<Plug>(bullets-newline)'],
97+
\
98+
\ ['vmap', 'gN', '<Plug>(bullets-renumber)'],
99+
\ ['nmap', 'gN', '<Plug>(bullets-renumber)'],
100+
\
101+
\ ['nmap', '<leader>x', '<Plug>(bullets-toggle-checkbox)'],
102+
\
103+
\ ['imap', '<C-t>', '<Plug>(bullets-demote)'],
104+
\ ['nmap', '>>', '<Plug>(bullets-demote)'],
105+
\ ['vmap', '>', '<Plug>(bullets-demote)'],
106+
\ ['imap', '<C-d>', '<Plug>(bullets-promote)'],
107+
\ ['nmap', '<<', '<Plug>(bullets-promote)'],
108+
\ ['vmap', '<', '<Plug>(bullets-promote)'],
109+
\ ]
110+
```
111+
82112
Enable/disable deleting the last empty bullet when hitting `<cr>` (insert mode) or `o` (normal mode):
83113

84114
```vim
@@ -184,7 +214,7 @@ let g:bullets_nested_checkboxes = 1 " default = 1
184214
" - [ ] child bullet [ type <leader>x ]
185215
" - [ ] sub-child
186216
" - [ ] child bullet
187-
"
217+
"
188218
" Result:
189219
" - [o] first bullet [ <- indicates partial completion of sub-tasks ]
190220
" - [X] child bullet
@@ -225,18 +255,18 @@ let g:bullets_checkbox_partials_toggle = 1 " default = 1
225255
" - [o] partially checked [ type <leader>x ]
226256
" - [x] sub bullet
227257
" - [ ] sub bullet
228-
"
258+
"
229259
" Result:
230260
" - [x] checked
231261
" - [x] sub bullet
232262
" - [x] sub bullet
233-
"
263+
"
234264
" Example 2:
235265
let g:bullets_checkbox_partials_toggle = 0
236266
" - [o] partially checked [ type <leader>x ]
237267
" - [x] sub bullet
238268
" - [ ] sub bullet
239-
"
269+
"
240270
" Result:
241271
" - [ ] checked
242272
" - [ ] sub bullet
@@ -269,7 +299,7 @@ let g:bullets_set_mappings = 0
269299
Add a leader key before default mappings:
270300

271301
```vim
272-
let g:bullets_mapping_leader = '<M-b>'
302+
let g:bullets_mapping_leader = '<M-b>'
273303
" Set <M-b> to the leader before all default mappings:
274304
" Example: renumbering becomes `<M-b>gN` instead of just `gN`
275305
```

plugin/bullets.vim

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ if !exists('g:bullets_mapping_leader')
3434
let g:bullets_mapping_leader = ''
3535
end
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+
3749
if !exists('g:bullets_delete_last_bullet_if_empty')
3850
let g:bullets_delete_last_bullet_if_empty = 1
3951
end
@@ -100,7 +112,7 @@ endif
100112

101113
" Parse Bullet Type ------------------------------------------- {{{
102114
fun! 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
10181054
augroup END
10191055
" --------------------------------------------------------- }}}
10201056

0 commit comments

Comments
 (0)