I use (neo)vim with mouse=a and scrolloff=5. Clicking on one of the top or bottom five lines with the mouse causes the screen to jump (so that the new cursor position is more centered), which distracts me. Is there any way to disable "so=5" for mouse-clicking only?
I use (neo)vim in different terminal emulators on linux.
You can disable the scrolloff value using a click mapping, refer :help <LeftMouse> However, you'll have to re-enable the scroll setting afterwards as re-enabling the setting in the mapping would again cause the view to jump up/down.
This will disable the scrolloff setting and the view will remain unchanged:
nnoremap <LeftMouse> :let &so=0<cr><LeftMouse>
With the above, the view will not jump, but you'll have to re-enable so
We could re-enable it in the same mapping, but that would mean, you'll see the same behavior of view jumping up or down as so is applied immediately after it's set.
nnoremap <LeftMouse> :let temp=&so<cr>:let &so=0<cr><LeftMouse>:let &so=temp<cr>
So, there isn't an ideal solution to what yo want (at least I know of). You could either disable so completely and use something like zz or get used to the behavior of so on mouse click.
Related
I am thinking about a plugin to show and hide nerdtree automatically. The nerdtree is shown when mouse is in the first 5 columns, and hide when the mouse is out of the first 10 columns. However, I cannot find the mouse movement events and mouse position api in the vim. Is there a method to get mouse movement in vim or vim-python?
PS: I mean the mouse movement instead of the cursor movement. To toggle NerdTree by cursor position I think it is not a good idea.
You can hook into mouse clicks via :nnoremap <LeftMouse> ..., but as that is supposed to set the current cursor position, it would be more consistent to also hook into equivalent cursor position changes via the keyboard. But having a NerdTree side panel slide in and out based on the cursor position in the buffer feels very odd... What I'm trying to say is: This is a bad approach for Vim.
Vim (even graphical GVIM) is a text editor with cell addressing. In the terminal, there's no way to get the current mouse position (without clicking); it's not part of the protocol: The mouse didn't exist when terminals were invented; and its support was grafted on much later. Now, GVIM could theoretically implement this, but it chooses to remain as close to the terminal as possible (cp. :help design-not).
alternative approaches
In Vim, everything is key-based, and the different modes make key mappings short, memorable, and often without modifier keys like Ctrl or Alt. I would map either an (unused) function key (<F3>), or combo (<Leader>t):
:nnoremap <Leader>t :NERDTreeToggle<CR>
I am having issues with my vim setup. If I click, or if I scroll with the mouse inside vim, I get a strange behavior. Those actions sometimes change my mode to insert and copy or paste things from the register, or insert random characters.
I do not know when the problem started since I do not use my mouse too often inside vim. However, sometimes I click or scroll on my window, and these commands are messing up my document.
I am using arch with i3 and uxrvt. I would also share my .vimrc file, but I am new here, so I do not know if I should just copy and paste it.
I noticed that if I open vim with xterm instead of uxrvt, the mouse clicks and scrolls refresh the cursor and place it at the middle of the screen and to the left.
I have set the option set mouse=a in my .vimrc
Please help me :)
Ok, I figured it out what was the issue. At some point, I mapped this command: nnoremap <esc> :noh<return><esc> to disable the highlighted results of a search after pressing <esc>
When reading :h set ttymouse, I realized that the mouse clicks and scrolls return <esc> and some other characters to the editor. This, together with my remapping of <esc> was messing up the return values of my mouse.
I fixed it by removing my remapping of <esc>, but I would like to use that mapping without messing my mouse :(
I have set a high value for scrolloff, which works really well for me when I am moving around with the keyboard. However, any time I try to select something with the mouse in an off-center line (so that I can copy some text), that line jumps to the center, preventing me from selecting that text. Is there a way to keep the scrolloff setting but prevent a mouse click from moving the cursor to that line?
I don't believe that there is a way to use an autocmd to set scrolloff=0 when using the mouse, but you could map a key to toggle between scrolloff=0 and scrolloff=50(or whatever value you are using) and just use that mapping before selecting text:
map <silent> <Leader>m :exec &scrolloff==0? "set scrolloff=50" : "set scrolloff=0"<CR>
I'd like to remap a modified click in gvim (and also MacVim), but certain combinations of modifiers work while others do not. In gvim on a Linux box, I would like to insert "hello" anywhere I type:
:noremap <C-S-LeftMouse> <LeftMouse>ihello<ESC>
However, that command does not work: control-shift-click retains its original behavior. Yet I can remap control-click in gvim:
:noremap <C-LeftMouse> <LeftMouse>ihello<ESC>
In MacVim, command-shift-click <D-S-LeftMouse> is likewise unresponsive, as are most other modified clicks.
How can I actually remap the modified mouse clicks?
To remap the <C-LeftMouse> in MacVim, you should first disable the contextual menu:
defaults write org.vim.MacVim MMTranslateCtrlClick 0
Double modifier keys don't work in MacVim. It's a known limitation/bug.
:nnoremap <M-LeftMouse> <LeftMouse>ihello<Esc>
seems to work, though, but neither <C-LeftMouse> nor <D-LeftMouse> do.
<C-LeftMouse> brings the normal contextual menu everyone expects, I wouldn't count on it being easily changed.
<D-LeftMouse> does nothing at all. I wonder if it's even registered.
Is it possible to use vim with the mouse?
If so, how?
You can enable the mouse with :set mouse=a (The letter 'a' means enable it in all modes)
With GVim, you can select text and move the cursor, and select menu options with the mouse. Copy and paste, by right-clicking etc... But I guess this misses the point of using VIM.
You can map certain actions to mouse left click and right click. And there are plenty of already mapped actions to work with ctags and other things.
:help mouse-using