Is it possible to have a separate visual mode in the Split vim window when editing the same file?

When I open a file Foo.txtin vim and then use :vsplitit so that I can examine its different segments side by side, I notice that if I make any visual selection on the left, vim will select the same text on the right. In addition, if both sides are not lined up when I started the visual selection, which side to which I switch will jump according to the selected one.

I would like to be able to use visual mode to highlight different segments of text on two sides of a split window, or at least to be able to use visual mode to the left, and then to move the cursor to the right. This works fine if the two files are actually different files.

Is there any parameter that would enable this, or is this 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 is not an option that can be installed. If anyone has a good hack to get this behavior, please share. However, I will also be studying autocmd, although this most likely does not match my current knowledge in vimscript.

+5
source share
1 answer

It is as if vim is trying to be smart when it sees two identical files, and this intelligence should be turned off.

This “smartness” is an implementation detail in which the visual selection (precisely, labels '<,'>) is local to the buffer. As you noticed, different buffers can have (and remember) different options.

An alternative would be to make the visual selection window local. I assume that this approach was not chosen because often the exact selection range cannot be transferred to another buffer; the number and length of lines are different.

However, you can implement what you want with the help of :autocmdwhich save the labels '<,'>in the local local variable on WinLeaveand restore them from WinEnter.

+5
source

All Articles