Make 'virtualedit' global-local?

20 views
Skip to first unread message

Gary Johnson

unread,
Jul 13, 2021, 1:40:00 PM7/13/21
to vim...@googlegroups.com
Would there be a problem with making 'virtualedit' global-local
instead of just global, as it is now?

The problem I'm having is that I set virtualedit=all automatically
whenever I'm diffing two or more buffers so that I can move the
cursor vertically through either buffer and not have the windows
scroll to the left whenever the cursor moves to an empty line. When
I open a new buffer, it also has virtualedit=all and editing behaves
oddly, causing me to make mistakes and to take extra steps to work
around those oddities.

The most common situation is committing a file to a git repo using
Fugitive. I use :Gdiffsplit to see the changes, which sets
virtualedit=all, then ":Git add %" and "Git commit" to commit them.
":Git commit" opens a new buffer containing the usual Git commit
template and the cursor positioned at line 1, column 1. Typing 'a'
to begin adding text, as I would in any buffer, moves the cursor to
the right to column 2, leaving a virtual space in column 1. I can't
backspace over it because there is no space character there. There
are several ways to begin my commit comment in column 1, but all
involve doing something I wouldn't have to do if 'virtualedit' was
not set.

If making 'virtualedit' global-local seems OK, I can take a stab at
making that change, but I don't have much free time these days, so
it may be a while.

Regards,
Gary

Bram Moolenaar

unread,
Jul 13, 2021, 4:22:02 PM7/13/21
to vim...@googlegroups.com, Gary Johnson

Gary Johnson wrote:

> Would there be a problem with making 'virtualedit' global-local
> instead of just global, as it is now?
>
> The problem I'm having is that I set virtualedit=all automatically
> whenever I'm diffing two or more buffers so that I can move the
> cursor vertically through either buffer and not have the windows
> scroll to the left whenever the cursor moves to an empty line. When
> I open a new buffer, it also has virtualedit=all and editing behaves
> oddly, causing me to make mistakes and to take extra steps to work
> around those oddities.
>
> The most common situation is committing a file to a git repo using
> Fugitive. I use :Gdiffsplit to see the changes, which sets
> virtualedit=all, then ":Git add %" and "Git commit" to commit them.
> ":Git commit" opens a new buffer containing the usual Git commit
> template and the cursor positioned at line 1, column 1. Typing 'a'
> to begin adding text, as I would in any buffer, moves the cursor to
> the right to column 2, leaving a virtual space in column 1. I can't
> backspace over it because there is no space character there. There
> are several ways to begin my commit comment in column 1, but all
> involve doing something I wouldn't have to do if 'virtualedit' was
> not set.

Yes, this sounds like a good idea.

I wonder if it should be buffer-local or window-local? Thus is it
related to the contents of the buffer, or to how it's displayed?
When buffer-local you would keep the setting when editing the same
buffer again in another window, but you can't have two windows on the
same buffer with different 'virtualedit' values.

I suppose buffer-local makes most sense.

> If making 'virtualedit' global-local seems OK, I can take a stab at
> making that change, but I don't have much free time these days, so
> it may be a while.

It's not complicated, you can use another option as an example.

--
There are three kinds of persons: Those who can count and those who can't.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Gary Johnson

unread,
Jul 29, 2021, 2:36:35 PM7/29/21
to vim...@googlegroups.com
Now that I've used this a while longer, I think it would work better
if it was window-local rather than buffer-local. The state of
'virtualedit' is more a property of the editing task than it is of
the file type or buffer contents.

I noticed this while using Fugitive and diffing a file in a pair of
windows while having the same file open for editing in another
window. The latter window suddenly had virtualedit=all even though
I only wanted it set in those windows where 'diff' was set.

I don't think the feature has been released for long enough for
changing it to be a problem, if that's what we decide to do.
I don't know if there are any other difficulties with making this
window-local.

What do you think?

Regards,
Gary

Bram Moolenaar

unread,
Jul 29, 2021, 4:26:06 PM7/29/21
to vim...@googlegroups.com, Gary Johnson
We can still change it. Because of the special way how window-local
options work, they are remembered per buffer. This is explained under
":help local-options". Give it a try keeping this behavior in mind.

--
A KNIGHT rides into shot and hacks him to the ground. He rides off.
We stay for a moment on the glade. A MIDDLE-AGED LADY in a C. & A.
twin-set emerges from the trees and looks in horror at the body of her
HUSBAND.
MRS HISTORIAN: FRANK!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Reply all
Reply to author
Forward
0 new messages