diff src/textformat.c @ 26448:748793fcb4e2 v8.2.3754

patch 8.2.3754: undesired changing of the indent of the first formatted line Commit: https://github.com/vim/vim/commit/ecabb511074b3f56cdd5067553c947a291d04e17 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 6 19:51:01 2021 +0000 patch 8.2.3754: undesired changing of the indent of the first formatted line Problem: Undesired changing of the indent of the first formatted line. Solution: Do not indent the first formatted line.
author Bram Moolenaar <Bram@vim.org>
date Mon, 06 Dec 2021 21:00:05 +0100
parents 7108cee19a2c
children 9596c652420b
line wrap: on
line diff
--- a/src/textformat.c
+++ b/src/textformat.c
@@ -954,6 +954,7 @@ format_lines(
     int		smd_save;
     long	count;
     int		need_set_indent = TRUE;	// set indent of next paragraph
+    linenr_T	first_line = curwin->w_cursor.lnum;
     int		force_format = FALSE;
     int		old_State = State;
 
@@ -1073,8 +1074,13 @@ format_lines(
 		{
 		    int		indent = 0; // amount of indent needed
 
-		    // replace indent in first line with minimal number of
-		    // tabs and spaces, according to current options
+		    // Replace indent in first line of a paragraph with minimal
+		    // number of tabs and spaces, according to current options.
+		    // For the very first formatted line keep the current
+		    // indent.
+		    if (curwin->w_cursor.lnum == first_line)
+			indent = get_indent();
+		    else
 # ifdef FEAT_LISP
 		    if (curbuf->b_p_lisp)
 			indent = get_lisp_indent();