Enable mouse scrolling but not visual mouse selection in vim?

I recently turned on mouse mode in vim:

set mouse=a 

I love to scroll, but terribly highlight the text. I am using vim in iTerm2 on Mac. Now, when I select the text, it is very slowly selected (it is selected only after dragging and dropping the selection), and the selected text is not automatically copied to my clipboard, as it was when using iTerm2 to select.

Is there a way to enable mouse or trackpad scrolling in vim without using the mouse to select text in visual display mode?

I tried:

 set mouse=n 

This prevents text from being highlighted when you try and select, but also prevents iTerm2 text from being highlighted.

Update:

Thanks to this post, I realized that I can achieve almost what I want by holding the option key, but this is pretty tedious. I would really like not to hold down the select key every time I select. Thoughts?

Update2:

Thanks to the suggestions in the comments, I managed to get closer. I needed to recompile vim so that +clipboard was turned on:

 brew install vim 

Now, if I’m ready to put up with the fact that I don’t perform selection as selected text, I can at least still get it to the clipboard by pulling it out after choosing the visual mode. And if I really need a better ergonomics of choice, I can hold on to the alt/option and get the original iTerm2 choice behavior.

I would like to change these modes. For example, by default, the behavior that is executed is by holding down the alt/option and activating the behavior of the visual mode when I want it using the key ... but, oh, well, that's good enough.

+6
source share
3 answers

short answer: I think this is impossible!

But it is usually difficult to prove the absence of an answer. Therefore, I will try to talk about this and I hope that I am wrong. So here is the long answer:

Your terminal, under "normal" conditions, processes the mouse, and the command-line application does not know anything about it. But sometimes the application requests terminal capabilities management to be able to bind mouse events to stuff.

This is what happens when you set mouse = a: you change the capabilities of your terminal to indicate that all mouse events are directed to the running application, so before or after vim, bind or not perform actions (such as scrolling, pasting, etc. )

So, when you use the option key to be able to choose, even though the running application has cursor control, it is to hack into the terminal emulator (iTerm2 in your case) to get the behavior that you are actually expecting.

My advice for you would be to switch to macvim ( brew install macvim ) which installs the gui interface for vim. And then you will have a choice that works great, although it just leaves the terminal.

+1
source

With your update, you say that you can almost get what you want, but that the selection is not automatically copied.

To do this, you just need to set clipboard+=autoselect guioptions+=a

See :help clipboard-autoselect .

+1
source

The best I have found is to add a switch for mouse mode.

Adding the following to .vimrc will switch from mouse=a to mouse= and vice versa when you press the key,:

 noremap , :if &mouse == "" \| set mouse=a \| else \| set mouse= \| endif<CR><CR> 
+1
source

Source: https://habr.com/ru/post/983338/


All Articles