when calling narrowed region buffer &nolinebreak is set
Closed this issue · 11 comments
Call <plug>NrrwRgnDo
on a text in a text file. Then nolinebreak
is set in the currently opened buffer and rests set even after quitting the narrowed buffer.
cannot reproduce
Under OpenSUSE 42.1, Vim 8.045, and a file .vim/viminrc
containing
set nocompatible
" Load plugin
let &rtp = '~/.vim/plugged/NrrwRgn/,' . &rtp
" let &rtp .= ',~/.vim/plugged/NrrwRgn/after'
filetype plugin indent on
syntax enable
" options go here
set linebreak
Then call vim -u ~/.vim/viminrc ~/test.txt
with test.txt
containing
test
and hit <leader>nrip
. Then ZZ
. Then :set linebreak?
shows nolinebreak
. Expected: linebreak
.
Okay, I see this now as well. However, NrrwRgn does not mess with the linebreak option. Vim internally resets linebreak in do_pending_operator(). I believe this is one place where it leaks to the user. I am not sure this is a bug however. You might be able to work around it by using hooks.
Why is it not a bug but intended to unset linebreak when using an operator?
As a user, it is inconsistent to unset linebreak when using the operator but not when using visual mode. What's the rationale behind it?
Because setting linebreak changes columns and to make working with text consistent, Vim resets linebreak internally.
That makes things easier internally for Vim, but doesn't respect the user's settings. If a behavior helps the coder, but disrespects the user, it better not be called a feature but a bug.
With latest Master, the issue persists.
yes of course, it is a vim problem. This patch fixes it:
diff --git a/src/normal.c b/src/normal.c
index 99ced41..17f58a6 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -1995,6 +1995,12 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
break;
case OP_FUNCTION:
+#ifdef FEAT_LINEBREAK
+ /* Restore linebreak, so that when the user edits it looks as
+ * before. */
+ if (curwin->w_p_lbr != lbr_saved)
+ curwin->w_p_lbr = lbr_saved;
+#endif
op_function(oap); /* call 'operatorfunc' */
break;
I'll probably clean it up a bit and submit it soon (but I need to create a test first)
Ah, do_pending_operator is in the source code of Vim. Impressive, thanks for having dug into it.
should be fixed with Vim 8.0.66