Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,34 @@ let g:bullets_custom_mappings = [
\ ]
```

Enable/disable deleting the last empty bullet when hitting `<cr>` (insert mode) or `o` (normal mode):
Enable/disable deleting or promoting the last empty bullet when hitting `<cr>` (insert mode) or `o` (normal mode):

```vim
let g:bullets_delete_last_bullet_if_empty = 0 " default = 1
" Example (| is cursor):
" - text
" - text
" - |

let g:bullets_delete_last_bullet_if_empty = 1 " default = 1
" - text
" - text
" |

let g:bullets_delete_last_bullet_if_empty = 0
" - text
" - text
" -
" |

let g:bullets_delete_last_bullet_if_empty = 2
" - text
" - text
" - |
"
" again:
" - text
" - text
" |
```

Line spacing between bullets (1 = no blank lines, 2 = one blank line, etc.):
Expand Down
6 changes: 5 additions & 1 deletion doc/bullets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ To add a leader key to all mappings set the following:
This will set the <space> key as leader to all default mappings.


Disabling empty bullet deletion
Empty bullet deletion
-------------------------------
By default bullets.vim will delete trailing empty bullets when the return key
is pressed, just like modern word processors.
Expand All @@ -157,6 +157,10 @@ If you would like to turn this feature off add the following to your .vimrc

`let g:bullets_delete_last_bullet_if_empty = 0`

If you would like to promote bullet instead of deleting it, add the following to your .vimrc

`let g:bullets_delete_last_bullet_if_empty = 2`


Maintain right padding on bullets
---------------------------------
Expand Down
6 changes: 5 additions & 1 deletion plugin/bullets.vim
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,11 @@ fun! s:insert_new_bullet()
" We don't want to create a new bullet if the previous one was not used,
" instead we want to delete the empty bullet - like word processors do
if g:bullets_delete_last_bullet_if_empty
call setline(l:curr_line_num, '')
if g:bullets_delete_last_bullet_if_empty == 1
call setline(l:curr_line_num, '')
elseif g:bullets_delete_last_bullet_if_empty == 2
call <SID>change_bullet_level(1, 0)
endif
let l:send_return = 0
endif
elseif !(l:bullet.bullet_type ==# 'abc' && s:abc2dec(l:bullet.bullet) + 1 > s:abc_max)
Expand Down
25 changes: 25 additions & 0 deletions spec/bullets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,31 @@
TEXT
end

it 'promote the last bullet when configured to' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
# Hello there
- this is the first bullet
- this is the second bullet
TEXT

vim.command 'let g:bullets_delete_last_bullet_if_empty = 2'
vim.edit filename
vim.type 'GA'
vim.feedkeys '\<cr>'
vim.feedkeys '\<cr>'
vim.write

file_contents = IO.read(filename)

expect(file_contents.strip).to eq normalize_string_indent(<<-TEXT)
# Hello there
- this is the first bullet
- this is the second bullet
-
TEXT
end

it 'does not delete the last bullet when configured not to' do
filename = "#{SecureRandom.hex(6)}.txt"
write_file(filename, <<-TEXT)
Expand Down
Loading