aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-05 15:06:37 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-05 15:08:41 +0800
commit04ba37773e5755375f4fa3f5af23cbbdb5eb5fc8 (patch)
tree41a74ebfc1835c86563849903988459d4fba0dca /src/nvim/ops.c
parent42863634dd83d70710436bb599b13571d734c662 (diff)
downloadrneovim-04ba37773e5755375f4fa3f5af23cbbdb5eb5fc8.tar.gz
rneovim-04ba37773e5755375f4fa3f5af23cbbdb5eb5fc8.tar.bz2
rneovim-04ba37773e5755375f4fa3f5af23cbbdb5eb5fc8.zip
vim-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. https://github.com/vim/vim/commit/ecabb511074b3f56cdd5067553c947a291d04e17
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index cd7ae25a20..f2859bf707 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -4421,6 +4421,7 @@ void format_lines(linenr_T line_count, int avoid_fex)
int smd_save;
long count;
bool need_set_indent = true; // set indent of next paragraph
+ linenr_T first_line = curwin->w_cursor.lnum;
bool force_format = false;
const int old_State = State;
@@ -4549,9 +4550,13 @@ void format_lines(linenr_T line_count, int avoid_fex)
if (need_set_indent) {
int indent = 0; // amount of indent needed
- // replace indent in first line with minimal number of
- // tabs and spaces, according to current options
- if (curbuf->b_p_lisp) {
+ // 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 if (curbuf->b_p_lisp) {
indent = get_lisp_indent();
} else {
if (cindent_on()) {