When I open a file Foo.txt
in vim, and then use :vsplit
so that I can examine different segments of it side-by-side, I notice that if I do any kind of visual selection on the left, vim will select the same text on the right. Furthermore, if the two sides are not lined up when I started the visual selection, whichever side I switch to will jump to match the one that was selected.
I would like to be able to use visual mode to highlight different segments of the text on the two sides of the split window, or at least to be able to use visual mode on the left and then move my cursor to the right. This works perfectly fine if the two files are actually different files.
Is there some option that would enable this, or is the only way to make a copy of the file?
Edit: I am expanding the scope of this question to include any vimscript-based solutions, since it does not seem to be an option that can be set. If someone has a nice hack for getting this behavior, please share. I will also be looking into autocmd in the meantime, although it is most likely beyond my current knowledge in vimscript.
It is as if vim is trying to be clever when it sees two same files, and this cleverness should be disableable.
This "cleverness" is the implementation detail that the visual selection (precisely, the '<,'>
marks) is local to the buffer. As you have observed, different buffers can have (and remember) different selections.
The alternative would be to make the visual selection window-local. I guess that approach wasn't chosen because often, the exact selection range cannot be transferred to another buffer; the number and lengths of lines are different.
That said, you can probably implement what you want with :autocmd
s that save the '<,'>
marks in a window-local variable on WinLeave
and restore from those on WinEnter
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With