[vim/vim] YAML: Extra indentation when writing key: value lines (Issue #13845)

78 views
Skip to first unread message

Stephen

unread,
Jan 11, 2024, 2:18:10 PM1/11/24
to vim/vim, Subscribed

Steps to reproduce

  1. Set the following vimrc:
filetype plugin indent on
autocmd! FileType yaml setlocal autoindent smartindent expandtab sw=2 ts=2 sts=2
  1. Edit a yaml file and write a key: value, then press enter to move to the next line.
  2. The cursor is indented an extra level. (| is cursor)
key: val
  |

Expected behaviour

The cursor maintains the correct level of indentation.

key: val
|

PR #10328 describes this exact behavior, which was closed in favor of commit f4f579b. This was back in 2022. However, I've experienced this behavior for many years... I only just now decided to try and get to the bottom of it.

Version of Vim

9.1.016

Environment

OS: Fedora 39
Terminal: GNOME Terminal 3.50.1
$TERM: xterm-256color

This is a completely clean installation of F39. I also see the same behavior in Debian 12, openSUSE Tumbleweed, etc

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845@github.com>

Stephen

unread,
Jan 11, 2024, 6:26:58 PM1/11/24
to vim/vim, Subscribed

Found it! Reverting the file back to v9.0.0380 fixes the issue.
0daafaa#diff-723cc09b2d0f8f9383c670a8846979363fbc67a741aad1aae657242b8c2667a3L57


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845/1888125970@github.com>

Christian Brabandt

unread,
Feb 26, 2024, 4:20:38 PM2/26/24
to vim/vim, Subscribed

Reverting the diff is definitly wrong. The diff from v9.0.0379 fixes a syntax error. Try and search for it, you will get the following error: /\v%(%\x\x) : E678: Invalid character after %[dxouU].
Guessing from the yaml.vim indent script, where it goes wrong it is this one here:
https://github.com/vim/vim/blob/02d7a6c6cfceb3faf9c98fcb7c458760cd50d269/runtime/indent/yaml.vim#L145-L151

As mentioned in the comment below, this is trying to match the following item:

Mapping with: value
        that is multiline scalar

which is what is happening in your case (and seems to be correct).

I think this is intentionally, and once you type : the cursor position will jump back to the beginning of the line. So I think the current behaviour is right.

So it seems there is just a misunderstanding about whether or not the yaml.vim indent script should try to match a multiline scalar or whether it shouldn't. But given the work-around, that : dedents the line again, I would think the current behaviour is okay just perhaps a bit unexpected.

Having said all that, I haven't heard from @ZyX-I in a long time. So if anybody wants to volunteer to maintain this, please stand up :)

But be warned, that are some crazy Vim regexes here.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845/1965309665@github.com>

Christian Brabandt

unread,
Feb 26, 2024, 4:20:44 PM2/26/24
to vim/vim, Subscribed

Closed #13845 as not planned.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/13845/issue_event/11927757319@github.com>

liutaurasa

unread,
Feb 29, 2024, 5:24:16 AM2/29/24
to vim/vim, Subscribed

I want to disable that smart multiline indentation. I want my cursor to be on the same level as previous line. It is driving me crazy.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845/1970788435@github.com>

Christian Brabandt

unread,
Feb 29, 2024, 5:30:23 AM2/29/24
to vim/vim, Subscribed

remove those two lines from your copy then


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845/1970841766@github.com>

Stephen

unread,
Feb 29, 2024, 10:08:15 AM2/29/24
to vim/vim, Subscribed

Frightening regexes for sure! My two cents is that writing multiline scalars is less common than writing consecutive key-value pairs, so it seems odd to indent for them as the default behavior.

Either way, good to know what exactly is going on behind the scenes and which lines to modify.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845/1971341629@github.com>

Christian Brabandt

unread,
Feb 29, 2024, 10:45:45 AM2/29/24
to vim/vim, Subscribed

Reopened #13845.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/13845/issue_event/11967945098@github.com>

Christian Brabandt

unread,
Feb 29, 2024, 10:45:45 AM2/29/24
to vim/vim, Subscribed

Let me add a configure switch for people to opt-in into the multiline detection and include it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845/1971418481@github.com>

Stephen

unread,
Feb 29, 2024, 10:54:08 AM2/29/24
to vim/vim, Subscribed

Hey, thanks! I'll also note that I ended up commenting starting from line 141 since that does the same multiline scalar assumption for list items.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13845/1971435673@github.com>

Christian Brabandt

unread,
Feb 29, 2024, 11:30:51 AM2/29/24
to vim/vim, Subscribed

Closed #13845 as completed via b4eb3f1.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/13845/issue_event/11968549579@github.com>

Reply all
Reply to author
Forward
0 new messages