4

I've been having trouble understanding the behavior defined in GetRSTIndent() in indent/rst.vim. I'm specifically using Neovim v0.2.2, but I believe this file has not changed between Vim/Neovim.

Background and Behavior

The specific indent file I'm referring to is on the Neovim GitHub repo at this location.

The effect is as follows:

If I'm typing a list (numbered or bullet point), my indentation always carries over from the previous line, causing too much indentation. For example:

- First item<Enter>
  | <-- Cursor here.

- Item one<Enter>
  - Item two<Enter>
    - Item three

1. This is list item one<Enter>
   2. This is list item two<Enter>
         3. This is three<Enter>
                     4. This is four<Enter>
                                             5. This is five

In other words, for me to continue with my list with a new bullet point, I have to press <Backspace> or <C-D> to get back to the correct indentation level before typing my next item. (The situation is even more strange with numbered lists; I expect this is a bug.)

I checked on the "markdown" filetype and it does not have any of this strange indent behavior. In my opinion, the handling of the Markdown is as I would expect, but the handling of reStructuredText is counterintuitive (and, at least for me, a hassle).

Question

My question is two part:

  • Why might this behavior be explicitly hardcoded for the rst filetype?
  • Can anyone see a reason why I shouldn't submit this as a GitHub issue for the indent/rst.vim file?

If this is this simply undesired/counterintuitive behavior, I'd like to open an issue on the GitHub repo. I just want to make sure I understand the issue clearly. At this point, I know "what" the indent file is doing, but I don't understand "why." The code seems redundant to features (i.e. ':set formatoptions+=n') already present in Vim.

Workarounds for Present

For anyone who stumbles on this simply trying to fix the issue, here is how I have been able to do so at present:

Use :set indentexpr="" to avoid the behavior when editing reStructuredText (or edit the indent/rst.vim file directly to avoid using GetRSTIndent())

If desired, the same affect can be obtained using :set formatoptions+=n. This also has the benefit of only wrapping when the line wraps automatically according to 'textwidth' (Instead, the GetRSTIndent() increases indent every time you press <Enter> to start a new item--almost certainly not what you want!)

For further ideas on how to handle RST indentation, please also see this question: How to avoid indenting after a line that starts with a number?

1

My hunch is that the author of the plugin always includes a blank line between their list items. Note that if you press Enter a second time, without first entering any further text, the cursor moves back out to the indent level of the list item.

According to the spec, this blank line is optional (although none of the examples in the primer omit it), so I think you can probably report this as a bug. (You should perhaps first check whether adding an issue to the GitHub repo is the mechanism for doing so that the Neovim maintainers favour: for Vim I believe it's suggested you should contact the plugin author directly, initially.)

I guess I can see some utility in the current implementation: if you're willing to always include the extra vertical spacing, it allows you to either create a sublist (by typing a new bullet point) or not (by pressing Enter and then adding the bullet) without having to adjust indentation manually at all.

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.