Can't make work ScrollWheel map in vim - vim

I have a little problem with mapping vim shortcuts for my mouse wheel. I can't make this work :
set mouse=a
set nowrap
noremap <C-ScrollWheelUp> 3zh
noremap <C-ScrollWheelDown> 3zl
On the other hand, the following is working (but not convenient, i just tested it to see if ScrollWheelUp/Down was working) :
set mouse=a
set nowrap
noremap <ScrollWheelUp> 3zh
noremap <ScrollWheelDown> 3zl
What is my problem ?

Related

Vim showing random trailing colors on wsl

Every time I use a colorscheme for vim(WSL) from Github it shows some trailing colors normally within the first 10 lines and sometimes for the entire code like in the link. At first, I thought that it was just highlighting the trailing spaces, but even after removing them, it reverts to its original form on changing cursor locations. Pretty new to vim, so please help me.
My .vimrc:
set nocompatible
set clipboard=unnamed
set clipboard=unnamedplus
syntax on
set tabstop=4
set shiftwidth=4
set autoindent
set smartindent
set shortmess+=I
set number
set termguicolors
set relativenumber
set laststatus=2
set backspace=indent,eol,start
set hidden
set ignorecase
set smartcase
set incsearch
nmap Q <Nop> " 'Q' in normal mode enters Ex mode. You almost never want this.
set noerrorbells visualbell t_vb=
set mouse+=a
colorscheme pablo
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>
inoremap <Left> <ESC>:echoe "Use h"<CR>
inoremap <Right> <ESC>:echoe "Use l"<CR>
inoremap <Up> <ESC>:echoe "Use k"<CR>
inoremap <Down> <ESC>:echoe "Use j"<CR>
Update: Just found out after messing with stuff that it happens everytime I use ^D or ^U for page up - down. Now it happens even for the inbuilt colors. However does not happen if I use j or k. The only change I did with the .vimrc was adding the set termguicolors.
figured out that all my issues happens because of the termguicolors.
but this is included from every github has that and so all of them show this random colours. is there any way this can be fixed?
So, apparently the problem lies with windows, or the WSL to be precise. WSL does not seem to support the set termguicolors which is responsible for the weird colors appearing on screen. And because this is essential for several colorschemes (otherwise they look very different). So unless WSL2 provides this feature I don't think it is possible for windows to have any of the fancy colorschemes. The best option is to probably use a virtual machine and run linux or dual-boot your device.

Navigate in gvim like in most

I'd like to use gvim to view files with long lines. It's a table, so I'm not wrapping the lines.
Is this possible to configure gvim so arrows navigation will be like in "most" tool? Arrow key will move the whole screen 1 character lef/right/top/bottom?
Thanks a lot.
I think this should do what you want.
set nocompatible
set nowrap
set virtualedit=all
nnoremap <Left> zh
nnoremap <Right> zl
nnoremap <Up> <C-y>
nnoremap <Down> <C-e>
If you want the same behavior in insert mode, add the same mappings again as a second set, but use inoremap instead of nnoremap.
The virtualedit setting will allow the cursor to move beyond the end of the line and continue on as if the line had infinite whitespace to the right.
NOTE: virtualedit is only available if Vim was compiled with that feature. You can check with :version. If this feature is available, you should see a + next to it, e.g. +virtualedit.

Insert mode Ctrl-O without triggering autocmds

Having gone the full circle from default statusline, to customized, through neatstatus, powerline, airline and back to customized statusline, one of the fancy features was a coloured statusline depending on mode. So, a couple of autocmds to trigger a colour change on InsertEnter and InsertLeave, and all is nice, snappy, with a visual colour cue, and pretty much all in
set statusline=%-22.(%5l\ of\ %5L,%4c:%4v%)\ %P\ %6o\ %03b\ %<%F\ %y\ %h%m%r%=b:%2n\ %{strftime('%a\ %b\ %e\ %I:%M\ %p')}
But, Insert Mode Ctrl-O actually triggers the autocmds, and I like to have Up and Down imapped to gk gj, to move by display line and not entire wrapped lines. This can cause quite a bit of barely noticeable colour change flicker (the worst kind) during those times when quick scrolling through a file while in Insert mode. (This happens quite often when coding COBOL, when you need to scroll back and forth between DATA DIVISION and PROCEDURE DIVISION, but that's beside the point).
Anyway, I'll take the tsk-tsks for using cursor keys while in Insert mode, but I'm wondering if there is a way to
inoremap <Up> <C-O>gk
inoremap <Down> <C-O>gj
without triggering the InsertLeave InsertEnter autocmds, that repaint the statusline just to change the colour, pretty needlessly in this case. Or a different way to use cursor keys in Insert mode that move by display line and not wrapped line.
I thought only about really simple way how to do it
inoremap <Up> <C-c>gka
inoremap <Down> <C-c>gja
i_CTRL-c doesn't trigger InsertLeave autocommand event so I hope in your case it means no flash.
Then I found this excellent Ingo Karkat's answer:
function! IgnoreOn( motion )
set eventignore+=InsertLeave,InsertEnter
return "\<C-o>" . a:motion
endfunction
function! IgnoreOff()
set eventignore-=InsertLeave,InsertEnter
return "\<Left>\<Right>" | " Workaround for missing screen update.
endfunction
inoremap <expr> <SID>IgnoreOff IgnoreOff()
inoremap <expr> <SID>IgnoredDown IgnoreOn('gj')
inoremap <script> <Down> <SID>IgnoredDown<SID>IgnoreOff
inoremap <expr> <SID>IgnoredUp IgnoreOn('gk')
inoremap <script> <Up> <SID>IgnoredUp<SID>IgnoreOff

Switch cursorline in vim on demand

In vim editor, I want to switch cursorline on and off on demand.
I already have this in my .vimrc:
set nocursorline
noremap <F3> :set cursorline! <CR>
But this only works in normal mode. How to change, so the F3 key works in insert mode too?
I don't want to have cursorline at opening a new file directly, so "set nocursorline" is OK for me.
I'll assume by "edit mode" you mean "insert mode". The trick for running normal mode commands from insert mode is to prefix them vith CTRL-O. Try this:
set nocursorline
nnoremap <F3> :set cursorline!<CR>
inoremap <F3> <C-o>:set cursorline!<CR>
map imap cmap noremap ... all do not solve my problem. Generally I want to use a key mapping definition which works in ex mode and edit mode at once.

Normal command map, tab is interpreted as literal

When I make a .vimrc entry,
nnoremap <silent> <leader>c :colorscheme <tab>
The tab is applied if I understand the terminalogy, as a literal, that is, upon typing ,c, I get in Vim command line,
:colorscheme ^I
I tried to internet the search terms, but mostly I get results about remapping Vim Tabs; the closest I found was somebody putting quotes around their <tab>, but I think that is for a different desired outcome.
I also have this, which is why I want the tab in my shortcut,
set wildmenu
set wildmode=longest:list,full
You'll need the 'wildcharm' option:
set wildcharm=<C-z>
nnoremap <silent> <leader>c :colorscheme <C-z>
See :help 'wildcharm'.
As a side note, I use that option with great effect for switching buffers:
nnoremap <leader>b :buffer <C-z><S-Tab>
and a file-opening variant would be just as easy and just as useful:
nnoremap <leader>e :edit <C-z><S-Tab>

Resources