Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue item numbering on enter #6

Closed
techntools opened this issue Jan 1, 2023 · 17 comments
Closed

Continue item numbering on enter #6

techntools opened this issue Jan 1, 2023 · 17 comments

Comments

@techntools
Copy link

After pressing enter, next item in list should get the item number automatically.

@lervag
Copy link
Owner

lervag commented Jan 1, 2023

lists.vim uses <c-a> (ctrl + a) for this. Can you first check if that works as expected for you? I.e., if you write a numbered list, e.g.

1. first line
2. second line
3. third line

if you now go to the end of the third line, then press enter, then <c-a> - does it now add the number as you want?

@techntools
Copy link
Author

Its not working. Its giving some random results.

In a file named hera.wiki:

1. first line
2. second line
3. third line
1. first line
2. second line
3. third line

@lervag
Copy link
Owner

lervag commented Jan 2, 2023

That's strange. On my side, that works exactly as expected... Let's simplify everything here:

  1. Open Vim from a terminal with vim (or nvim if you use neovim).
  2. Enable lists.vim with :ListsEnable.
  3. Start to write a list, e.g.
    1. first line
    
  4. Now, after <cr> press <c-a> (still in insert mode). What happens?

Also, what's the output of doing :imap <c-a>?

@techntools
Copy link
Author

Its working.

@lervag
Copy link
Owner

lervag commented Jan 6, 2023

Ok. Now, with that, you could possibly map <plug>(lists-new-element) in insert mode to <cr>. E.g.

imap <cr> <cr><plug>(lists-new-element)

However, this won't work quite as desired. You need something more advanced, because you don't want to add the new element except if the text just above is a list. There are likely many more edge cases that should be handled. And the map should only be applied when you enable lists.vim. Also, other plugins might suggest/want to remap <cr>.

This is precisely why I did not create this functionality. To me, it seems simpler and more robust to instead add a separate map for the action of "create new element/item/bullet".

@techntools
Copy link
Author

I do agree with the point of conflict with other plugin. And I do not mind one more keystroke for next line number.

What if you provided option to enable/disable completion ? Let the user be responsible what happens next.

@lervag
Copy link
Owner

lervag commented Jan 8, 2023

What if you provided option to enable/disable completion ?

Could you explain a bit more? I don't quite get what you mean, sorry.

@techntools
Copy link
Author

I meant something like let g:auto_next_item_number = v:true

@lervag
Copy link
Owner

lervag commented Jan 12, 2023

Sorry, but that's not very verbose. Can you explain how the option would work? Preferably with an example or two?

@techntools
Copy link
Author

I meant just set it in your vimrc and enable/disable auto completion if provided.

@lervag
Copy link
Owner

lervag commented Jan 16, 2023

What do you mean with auto completion?

I think I'm confused, because I wrote earlier:

This is precisely why I did not create this functionality. To me, it seems simpler and more robust to instead add a separate map for the action of "create new element/item/bullet".

To which you responded

I do agree with the point of conflict with other plugin. And I do not mind one more keystroke for next line number.

What if you provided option to enable/disable completion ? Let the user be responsible what happens next.

It seems you first agree that I should not add the feature, then you start talking about completion. Completion is in itself a specific concept in Vim/neovim, and what we are discussing is not completion (see :help ins-completion, for instance). However, it seems you are saying that you want me to still add the feature you wanted in the first place, only with an option to enable it. Is that right?

If so, I'm still not sure I want that, because, as I tried to explain, it is quite complicated and can easily go wrong.

@techntools
Copy link
Author

I agreed that the feature can cause issues. And I know the about keyword auto completion.

Your resistance to the feature may be right but I am right about its usefulness as well.

@lervag
Copy link
Owner

lervag commented Jan 17, 2023

Your resistance to the feature may be right but I am right about its usefulness as well.

I spend quite a lot of time writing and maintaining Vim plugins, and my time is unfortunately severely limited. "Resisting" feature requests is unfortunately important to avoid being overwhelmed. It does not mean that your request is bad or that you are wrong. It simply means that I am considering if this is what I want to spend my time doing.

Notice that my questions in this thread were not meant as resistance. Instead, I was genuinely trying to understand what you wanted/suggested so that I could be able to decide if it was something I was willing to implement from my side.

@techntools
Copy link
Author

I appreciate your time and effort the same way I understand about the feature request.

@realshovanshah
Copy link

realshovanshah commented Dec 3, 2023

Hey. First, thanks for this minimal plugin.

I'd also like to express my preference this behaviour — specifically for unordered lists. While <C-a> is a intuitive solution for for numbered lists, those that mostly work with unordered ones aren't used to needing an extra binding for this behaviour. Even if one were to get used to this, this'll get tedious rather quickly when working in workflows "based on the idea that list items are indented consistently".
(Perhaps it's also worth noting that the vim-esque <C-a> mapping, tends collide with the multiplexer's trigger making, rendering it to be one of the less purposeful Vim keys; and hence, the loss of its proposition of being intuitive.)

Let me know what you think of this. I think, just setting what Vim considers as comments should be enough to achieve this right? I remember using this to continue/auto-add comments in the past.

@lervag
Copy link
Owner

lervag commented Dec 5, 2023

Hey. First, thanks for this minimal plugin.

I'm glad you like it!

I'd also like to express my preference this behaviour — specifically for unordered lists. While <C-a> is a intuitive solution for for numbered lists, those that mostly work with unordered ones aren't used to needing an extra binding for this behaviour.

I mostly work with unordered lists. ;)

Even if one were to get used to this, this'll get tedious rather quickly when working in workflows "based on the idea that list items are indented consistently". (Perhaps it's also worth noting that the vim-esque <C-a> mapping, tends collide with the multiplexer's trigger making, rendering it to be one of the less purposeful Vim keys; and hence, the loss of its proposition of being intuitive.)

I'm an avid user of tmux. I use <c-q> as my prefix. I know <c-a> is a default prefix in e.g. screen, but IMHO you really should change it. <c-a> is very useful in Vim e.g. to increase value of numbers. See :help CTRL-A and related sections.

I think, just setting what Vim considers as comments should be enough to achieve this right? I remember using this to continue/auto-add comments in the past.

Yes, combined with 'formatoptions'. In fact, we already do change the 'comments' option; see:

setlocal comments+=fb:*,f:*\ TODO:,b:*\ [\ ],b:*\ [x]
setlocal comments+=fb:-,f:-\ TODO:,b:-\ [\ ],b:-\ [x]

The main thing to change here is to remove the f key in the comments option in e.g. fb:*. The f is added to explicitly avoid adding the new comment leader.

I personally prefer it to be the way it is. Also, if I were to add an option to not include the f key, then it seems strange to not also make the same option provide the feature asked for in the original request above concerning ordered lists. The latter is possibly much harder; I'm not sure.

@daviewales
Copy link

I too would like lists to automatically continue when I press Enter. However, lervag's reluctance is justified. bullets.vim does continue lists on Enter, but there are several bugs with the implementation, to the point that I have switched to lists.vim instead. It's easier to press <c-a> to add a new list item than to be confused why I'm unable to replay macros which add newlines...

I remain hopeful that someone will one day create a plugin which automatically continues lists without introducing conflicts and bugs. But until then, I'm happy to press <c-a>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants