10

Contracts etc formal things need numbered lists.

1. Some text

2. More text

 2.1. Sub-section text

etc.

The key is to eliminate the manual re-numbering when inserting or deleting a list item. Is this possible with vim? List numbering consistency is really difficult to keep track of manually.

One of the associated goals with this is to have proper revision control made possible by a non-obfuscated storage format, such as clear text.

  • 1
    If a PDF is acceptable, then unnumbered list markdown can be used to tag list items and asciidoc can later be used to convert the markdown into a PDF with line numbering. But I too would like to know how to use vim for automated line numbering of text-only files. – Wildcard Oct 12 '15 at 21:30
  • 1
    That's something word processors are quite good at. – romainl Oct 12 '15 at 21:31
  • @Wildcard PDF is indeed acceptable, the only thing is the initial anonymous tagging makes referring to specific numbered items across document difficult. But still, your method is definitely better than nothing. – lkraav Oct 12 '15 at 21:43
  • Would it be acceptable to use some form of markdown which would then be converted/unconverted automatically with an ex-mode command? e.g. prefix top level list items with - , second level list items with -- , etc. This seems the most likely avenue of approach; see my recent question about consecutive numbering in Ex-mode for a starting point. – Wildcard Oct 13 '15 at 18:09
  • Since options are scarce, anything goes. – lkraav Oct 13 '15 at 18:50
1

I have a plugin that can (Partially?) helps you: lazyList (No automatic list numbering).

In the following example (_ is the cursor position) ...

1. Some text
2. More text   
 Sub-secti_on text
 Sub-section text   
 Sub-section text

... simply execute the command :LazyList '2.%1%. ' to get:

1. Some text
2. More text   
 2.1. Sub-secti_on text
 2.2. Sub-section text   
 2.3. Sub-section text

To remove the indices, execute the same command.

By default, the indices are added to the current paragraph (Same indentation or when surrounded by empty lines), but you can add them to a visual selection.

A good way of doing in your case:

  1. Add indices
  2. Remove the indices before adding a new element(s).
  3. Add indices after adding the new element(s).

This video should be more explicit.

The bad thing with the plugin, is that it doesn't take in account a visual selection with empty lines, I should reconsider this behavior.

P.S English is not my native language, so please excuse the mistakes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.