You don't need anything that complex
You can even define your command to be
:command! ToggleMouse exe 'set mouse='.(empty(&mouse)?'a':'')
" Here I use `:exe` because I didn't want to use `:if` in a command definition which would look like:
:command! ToggleMouse if empty(&mouse) | set mouse=a | else | set ...
Your examples work fine for me on Vim 7.4.1689 and Neovim.
The following didn't work at first:
Then I read the following in :h 'mouse'
Enable the use of the mouse. Only works for certain terminals
(xterm, MS-DOS, Win32 |win32-mouse|, QNX pterm, *BSD console with
sysmouse and Linux console with gpm).
I use tmux a lot, so $TERM is set ...
Note: I have not tested this with gvim, only with normal vim
This piece of code allows me to scroll instead of selecting text when I drag using my mouse.
"mark b is the current cursor position
"mark a is the previous cursor position
Credits to Ingo Karkat, you just need to set foldcolumn for using the mouse to open and close folds. From :he fold-foldcolumn:
'foldcolumn' is a number, which sets the width for a column on the side of the
window to indicate folds. When it is zero, there is no foldcolumn. A normal
I understand that you are set up with the features necessary for copy and pasting with the system clipboard, but I want to be a tad redundant as those registers can be a tad challenging to set up. It's all about the features that are enabled with your install of Vim. In OS X and Linux, the clipboard feature needs to be enabled, and Linux usually also ...
The trick is to enable the mouse with :set mouse=a.
By default, Vim doesn't handle the mouse; the terminal emulator does, and from the terminal emulator's perspective "it's all text", it can't distinguish between your "number" or gutter.
gVim "emulates" a terminal emulator in many ways, and acts in the same way.
Then enabling the mouse, it's Vim that does ...
A good general rule when using Vim is to not use the mouse—Vim is designed from the ground up to be used with keyboard commands. In order to copy text, you can use the y command to yank a particular selection or chunk of text. Like all other Vim commands, you can think of y as a verb and give it modifiers, like y2j to yank the current line and the next ...
I figured out a way to do that with Hammerspoon
and clever usage of mapping.
The first part is configuring Shift + ScrollUp and
Shift + ScrollDown to scroll horizontally. In
order to do that, you have put the following code snippet in your .vimrc:
nnoremap <S-ScrollWheelUp> <ScrollWheelLeft>
nnoremap <S-2-ScrollWheelUp> <2-...
According to :help scroll-mouse-wheel the answer is no if you are using the Win32 GUI.
On the other hand, using X11 GUI or console vim with mouse support, the wheel sends key presses that you can remap.
So, you could get the behaviour you describe by
:nmap <ScrollWheelUp> h
:nmap <ScrollWheelDown> l
Note that I'm using nmap for mapping in ...
I want to take a shot at answering my first question on this forum. If I understand your question right, you are referring to concepts of "clipboard" and "primary". If not - sorry, I am wrong.
Note: After the comment by @jjaderberg below, I decided to clarify why I assumed that xterm_clipboard in vim is Primary. To be sure I looked up Clipboard definition ...
EDIT: One problem with my original function is that you get annoying lag when using it at near the top/bottom of the document (the cursor tries to scroll up from line 1), and that the cursor does not move at all when near the top/bottom of the document.
The updated version below fixes these issues and makes scrolling more similar to the behavior of Ctrl-U ...
OK. So this does not use the mouse.
But that's the whole point of vim (not needing to use the mouse).
You can use the vim normal copy command (which will not select the line numbers). To get it into the system clipboard just use the buffer *
"*<Normal Yank Command>
You have now yanked the text you want into the system clipboard and it can be pasted ...
You can use fn to bypass Mouse Reporting for programs like vim. (i.e. do fn+left-mouse button to clear the selection.)
(If you are not using a Mac and you are having a similar issue, you can use ctrl-z to suspend vim. Once you are done doing whatever, execute the ...
It works for me. I have ForwardX11 yes in my ~/.ssh/config file, which should have the same effect as running ssh with -X, and I started vim on the remote machine as vim -N -u NONE -i NONE to make sure my configuration wasn't affecting anything, then executed :set mouse=a. I entered some text into vim, then selected some of it with the mouse, then pasted it ...
Here's a heavy solution:
nnoremap <LeftMouse> ma<LeftMouse>`a
It will let the click go through (thus changing the focus), but make sure the cursor always goes back to where it was before the click was initiated.
I guess mouse clicks don't update the jump list. (:help jump-motions seems to confirm this is the case.)
Try this, for the async solution:
autocmd FocusLost * set mouse=
autocmd FocusGained * call timer_start(200, 'ReenableMouse')
Note that this ...
The behaviour you request is essentially impossible to achieve in Vim, because of two immutable facts:
When in visual mode, the cursor is always at one end of the selection. With the exception of jumping to the other end of the selection by pressing o, if you move the cursor, you are by definition altering the selection,
The cursor is always visible on ...
This might work if you put it at the end of your .vimrc
It's probaly not Vim that takes the mouse input, but rather your Terminal-emulator. To disable mouse support on your terminal this might help.
This is only a partial solution at best, but you can globally disable the mouse/touchpad while vim is running with xinput in a shell script:
xinput set-prop $ID "Device Enabled" 0
xinput set-prop $ID "Device Enabled" 1
When you're ready to have the touchpad work again.
Use xinput --list to get the id of your pointing device.
The use of the mouse is controlled (as you find out) with the mouse setting. It is activated only if mouse is equal to "something". This something determines when is the mouse used.
To disable the mouse you can simply:
Also in your function, you can call the set command directly: