neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 4faf23679e0c90b86466fa57cb5d97641ceb9a16
parent 03e9797bb21c77084cf1558405649a6bd6c4c15e
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Fri,  9 Jan 2026 09:37:04 +0800

vim-patch:9179ddc: runtime(yaml): update YAML indentation for mapping keys inside list items

When a list item contains a mapping key (e.g., '- element1:'), the
content under that key was incorrectly indented. The indent function
was not accounting for the '- ' prefix when calculating indentation
for nested content.

Example that now works correctly:
  list:
    - element1:
        foo: bar  # Now correctly at indent 6, not 4

The fix adds special handling in two places:
1. When previous line ends with ':' and starts with '- '
2. When looking up previous mapping key that is a list item

Fixes indentation to account for the 2-character '- ' prefix.

fixes:  vim/vim#18943
closes: vim/vim#19133

https://github.com/vim/vim/commit/9179ddc0608813e9dd7cf9ba856d61669d6f0e3a

Co-authored-by: Cezar Dimoiu <cezar.dimoiu@keysight.com>

Diffstat:
Mruntime/indent/yaml.vim | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/runtime/indent/yaml.vim b/runtime/indent/yaml.vim @@ -5,6 +5,7 @@ " Last Change: 2022 Jun 17 " 2024 Feb 29 by Vim project: disable mulitline indent by default " 2024 Aug 14 by Vim project: fix re-indenting when commenting out lines +" 2026 Jan 08 by Vim project: fix object indentation in array " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -114,7 +115,13 @@ function GetYAMLIndent(lnum) " " - |- " Block scalar without indentation indicator - return previndent+shiftwidth() + if prevline =~# '^\s*-\s.*:$' + " Special case: list item with mapping key (- key:) + " Need to account for the "- " prefix + return previndent + 2 + shiftwidth() + else + return previndent+shiftwidth() + endif elseif prevline =~# '\v[:-]\ [|>]%(\d+[+\-]?|[+\-]?\d+)%(\#.*|\s*)$' " - |+2 " block scalar with indentation indicator @@ -136,7 +143,10 @@ function GetYAMLIndent(lnum) let prevmapline = s:FindPrevLEIndentedLineMatchingRegex(a:lnum, \ s:mapkeyregex) if getline(prevmapline) =~# '^\s*- ' - return indent(prevmapline) + 2 + " Previous mapping key is in a list item (- key:) + " The key effectively starts at indent + 2 (after "- ") + " Content under it should be indented relative to the key position + return indent(prevmapline) + 2 + shiftwidth() else return indent(prevmapline) endif