Mac – How to improve into vim of MacOS Mojave the speed of vertical scroll with bottom/up keys

keyboardmacvimscrollingterminalvi

I transfer the original post from StackOverflow (Original post) to here since this is about Apple specificity.

I have a new macbook with Mojave and vim already installed.

Unfortunately, even for small source files, the cursor is very fast when I browse the current part of file where I am located but it becomes very slow when I am over this current page (the same thing occurs if I am over or lower this part) with down/up keys.

I don't talk about "mouse scrolling speed" but scrolling with down/up keys.

I saw and tried to apply different suggested solutions on web but none of these work for me (disable cursorline, using an empty ~/.vimrc , etc …).

Maybe threre is a conflict with some options in my ~/.vimrc.
Here below my ~/.vimrc:

set encoding=utf-8
scriptencoding utf-8
set ic
command Il :%s/^/\=line('.'). ' '
set hlsearch
set shiftwidth=2        " number of spaces to use for auto indent
set autoindent          " copy indent from current line when starting a new line
set nu
syntax on               " syntax highlighting
set backspace=indent,eol,start " delete with backspace 
"TOhtml
let html_use_css=1
let html_number_lines=1
let html_no_pre=0
highlight DiffAdd    cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText   cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red

I have changed into System Preferences the delay between 2 repeated keys to a small value :

So, into the default Terminal of Mojave macbook, I can move quickly with left/right keys on the command line.

Is there a relation between this small delay I have set and this slow scroll vertically with donw/up keys into vim ?

Another bug which must be known is that some commented code parts (for example when editing Python code with vim) appears as not commented when scrolling with down/up keys and also the contrary occurs : anyone has already got this strange behavior ? this problem doesn't happen when I browse file with CTRL+F or CTRL+B shortcuts.

Any help is welcome, Regards

UPDATE 1 :

Finally, I get to increase speed with the following link :

https://rehmann.co/blog/better-key-rates-osx/

I decided to switch to iterm2. So, as partial conclusion, the solution was to set fatest options in System Preferences and put into ~/.bashrc :

#disable special characters when holding keys
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

# normal minimum is 15 (225 ms)
defaults write -g InitialKeyRepeat -float 10.0
defaults write NSGlobalDomain InitialKeyRepeat -float 10.0

# normal minimum is 2 (30 ms)
defaults write NSGlobalDomain KeyRepeat -float 1.0
defaults write -g KeyRepeat -float 1.0
############# Enable spees ######################

It might be even too fast. That's why I wonder if there is a way to apply this big speed only for selected keys, i.e in my case, I would like to have this behavior for only down/up and left/right keys and NOT for the others keys (letters or special characters) ?

Is it possible to get this behavior ?

UPDATE 2 : Ok, I have finally found the trick : in iterm2 terminal, there is a GPU rendering option on below image :

GPU rendering

If you have no power on, GPU rendering was by default disable like, so uncheck the first box to be able to benefit from GPU rendering when computer is on battery :

Uncheck first option to  avoid GPU rendering disabled

That's all !

Best Answer

How to improve into vim of MacOS Mojave the speed of vertical scroll with bottom/up keys?

You didn't tell which Vim's variant you use, whereas there's no such thing as "standard Vim" in MacOS. In fact lots of things aren't described either, including Terminal's window geometry (the more text is shown at once, the more CPU cycles it'd be needed to scroll it), Terminal's active profile (some of them are slimmer and others have somewhat complex graphics thanks to additional effects — "Silver Aerogel" is one example).

I use homebrew's version of Vim and can tell that its scrolling is quite fast (at least there's no slowness) both in Terminal and in iTerm2.

Hence, a few suggestions that logically follows:

  • Try changing either Vim or terminal (or both).
  • Try using GUI version (gvim) and compare its scrolling performance.

You can give a try to Activity Monitor's CPU monitoring (with shortest update interval possible) to see if it shows any major CPU consuming processes during scrolling in Vim.