Vim mouse wheel vertical scrolling just one line - vim

How do I need to adjust my vimrc to make vertical scrolling smoother? I want to achieve that one iteration of the mouse wheel just scrolls one instead of three lines.

try adding this into your vimrc:
map <ScrollWheelUp> <C-Y>
map <ScrollWheelDown> <C-E>
P.S. the best solution would be: don't use that mouse-wheel...

The relevant information is at :help scroll-mouse-wheel:
For the Win32 GUI the scroll action is hard coded. It works just like
dragging the scrollbar of the current window. How many lines are scrolled
depends on your mouse driver. If the scroll action causes input focus
problems, see intellimouse-wheel-problems.
For the X11 GUIs (Motif, Athena and GTK) scrolling the wheel generates key
presses <ScrollWheelUp>, <ScrollWheelDown>, <ScrollWheelLeft> and
<ScrollWheelRight>.
So, if you're on Windows, you can only influence this globally through your driver, whereas on X, you can do
:map <ScrollWheelUp> <C-Y>
etc.

Related

don't use scrolloff=5 for mouse clicks in (neo)vim

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.

How to get mouse movement and mouse position in VIM?

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>

In vim, mouse clicks and scrolls are seen as keystrokes and messing up my text

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 :(

Flickering screen when scrolling in Gvim

So in vim all kinds of scrolling works perfectly, but in Gvim when scrolling screen flickers, especially noticable on faster scrolls like pgdn/pgup, Ctrl+U and Ctrl+D. Same thing when I scroll by dragging slider with mouse. I tried different background colors, but it does not make any difference.
Any ideas how to fix this?
Ask the developer(s) to make sure that a screen redraw is double-buffered.
I remember running into this years ago when I was using plain, non-antialiased X11 draw calls in Gvim (around version 6.0). In that case, the drawing speed was not-noticeable. When using anything anti-aliased, I could observe the flicker.
Obviously, the double-buffering is not necessary for the original terminal code and I'm assuming that the GUI updates are derived from the original terminal update code.
NOTE: This answer is only here for a reference for future development.
I have encountered similar problem in Gvim on windows. During scrolling bottom and top line flickers, it's even worse with e.g. 10j.
I have been able to eliminate it completely by adding lines in my .vimrc:
set lazyredraw
nnoremap <silent> j j:redraw<CR>
nnoremap <silent> k k:redraw<CR>
My current workaround is to use Vim-Qt, which is a fork of Vim with the GUI being based on Qt instead of GTK. Although it does have some shortcomings like lack of scrollbars, lack of maintenance (last commit 2 years ago), its advantage is that it doesn't flicker at all.
My fork of Vim-Qt now implements the scrollbars, so if you need them, you may want to try it instead of original Vim-Qt.

How can I temporarily make the window I'm working on to be fullscreen in vim?

I use vim, and usually have more than one vertical/horizental window open, usually editing c++ header files alongside cpp files. How can I temporarily make the window I'm working on to be fullscreen, edit what I want, and then exit fullscreen?
By fullscreen I mean to fit vim window only, and not my total display screen.
Ctrl+W_ will maximize a window vertically.
Ctrl+W| will maximize a window horizontally.
So far as I'm aware, there is no way to restore the previous layout after these actions, but Ctrl+W= will resize all windows to equal sizes.
An option could be to pursue the editing in a new tab. The following command opens the active buffer into a new tab allowing you to see the buffer in the hole vim window.
:tab split
And close the tab when you're done:
:tabc
Edit:
You can always use the following command to use tt as a shortcut (or better add it to your .vimrc):
:noremap tt :tab split<CR>
and close is when you're done :
:wq
If I understand what you're asking, I think you'll find the ZoomWin plugin helpful (GitHub). If you've got a bunch of split windows, and you want to temporarily make the current window the only visible one, you can hit <C-w>o. When you want to revert to the previous split state, hit <C-w>o again.
[Edit] Note on key mappings:
The default key mapping for this plugin is <C-w>o, but that conflicts with a default Vim key mapping. By default, that does :only, which makes the current window the only window. If you'd like to retain that functionality, you can remap ZoomWin to another key. I remap it to <C-w>w, because I like to use the :only option as well. Here's my mapping:
nnoremap <silent> <C-w>w :ZoomWin<CR>
Note that this also overrides a default Vim mapping, related to moving to other visible windows (:help CTRL-W_w), but I never used that one anyway.
Use Ctrl w_ to maximize the current window vertically.
These are some useful commands that help work with windows:
:e filename - edit another file
:split filename - split window and load another file
ctrl-w up arrow - move cursor up a window
ctrl-w ctrl-w - move cursor to another window (cycle)
ctrl-w= - make all equal size
10 ctrl-w+ - increase window size by 10 lines
:vsplit file - vertical split
:sview file - same as split, but readonly
:hide - close current window
:only - keep only this window open
:ls - show current buffers
:b 2 - open buffer #2 in this window
I've tried ZoomWin and a few others. The problem is, they all destroy and try to re-create the windows. This is especially problematic with custom plugins like NERDTree, Tagbar and a few others. Icons and fonts are not drawn properly, sizes are messed up etc..
zoomwintab.vim is a simple zoom window plugin that uses vim's tabs feature to zoom into a window inspired by ZoomWin plugin but in a non-destructive manner.
https://github.com/troydm/zoomwintab.vim
I use Tmux, so I mapped it to <leader> z to stay in sync with tmux's <prefix> z
nnoremap <leader>z :ZoomWinTabToggle<CR>
An awesome plugin for toggling windows fullscreen is vim-maximizer.
After it's installed you can simply use <F3> (default shortcut) to toggle fullscreen on the window.
You can also customize the shortcut keys, for example if you wanted to use <C-w> z (similar to tmux shortcut):
nnoremap <silent><C-w>z :MaximizerToggle<CR>
vnoremap <silent><C-w>z :MaximizerToggle<CR>gv
inoremap <silent><C-w>z <C-o>:MaximizerToggle<CR>
Somehow the ZoomWin plugin did not work at all for me, my experience was kind of what arithran says. I couldn't find other plugins so I wrote this:
function! ToggleZoom(zoom)
if exists("t:restore_zoom") && (a:zoom == v:true || t:restore_zoom.win != winnr())
exec t:restore_zoom.cmd
unlet t:restore_zoom
elseif a:zoom
let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
exec "normal \<C-W>\|\<C-W>_"
endif
endfunction
augroup restorezoom
au WinEnter * silent! :call ToggleZoom(v:false)
augroup END
nnoremap <silent> <Leader>+ :call ToggleZoom(v:true)<CR>
It creates the effect. You use the mapped key (Leader and + in my case) to toggle between maximized / previous layout. If you change to another split in the same tab, maximization turns off.
Manoj somewhat answered with a lot more useful info, but as a first step this is what works for me:
:hide: Hide the current buffer - with a two-buffer split, this makes the other buffer full screen. Unlike :only, this command does not close unmodified buffers so you can unhide them.
:unhide: Re-create splits for each open buffer
The unhide command does not restore the previous layout, so you will have to manually rearrange your windows if needed ex. using one of these for simple vertical/horizontal splits (this is CTRL-W followed by the uppercase navigation letter - release CTRL-W before entering the letter):
CTRL-W SHIFT-H: Move window to the far left
CTRL-W SHIFT-J: Move window to the very bottom
CTRL-W SHIFT-K: Move window to the very top
CTRL-W SHIFT-L: Move window to the far right
These are the same keys used for navigation, without SHIFT (lowercase navigation letters):
CTRL-W H: Move focus to the left window
CTRL-W J: Move focus to the bottom window
CTRL-W K: Move focus to the top window
CTRL-W L: Move focus to the right window
The H, J, K and K keys alone move the cursor - arrow keys on the keyboard may work as well for navigation.

Resources