Vim plugin that makes GUI experience better under Windows:
- automates maximizing and restoring the window
- provides full screen functionality
- fixes the lower-right window border when maximized
- remembers the window position and size
Use your favorite plugin manager. I prefer vim-plug:
Plug 'GrzegorzKozub/vimdows'
This plugin uses g:VIMDOWS_SCREEN
variable stored in viminfo
to save and restore the window position and size. This depends on the following lines added somewhere to the top of your vimrc
. The first one enables GVim to store all-caps global variables in viminfo
and the other one reads it early:
let &viminfo = &viminfo . ',!'
try | rviminfo | catch | endtry
If you don't like this, set g:vimdows_screen_memento
to 0
to disable this functionality.
The plugin provides functions that aim to make GVim experience under Windows nicer. By default, some of them are mapped to keys and some run in a response to GVim events.
This is the only function in this plugin that is compatible with Neovim.
It returns a JSON object that describes the current screen resolution and scaling: { 'width': 3200, 'height': 1800, 'dpi': 240 }
. Example use:
if has('win32') && has('gui_running')
set guifont=Fira\ Code\ Retina:h12
let s:screen = eval(vimscreen#get_screen())
if s:screen.height == 1800 && s:screen.dpi == 240
set columns=127 lines=31
winpos 60 62
endif
endif
If this function gives you incorrect results, open your gvim.exe
properties, on the Compatibility tab press Change high DPI settings button, check Override high DPI scaling behavior checkbox and select Application in the corresponding dropdown. Or just import this Registry script:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"C:\\Program Files\\Neovim\\bin\\nvim-qt.exe"="~ HIGHDPIAWARE"
Return 1
if GVim is, respectively, maximized or in full screen and 0
otherwise.
The former maximizes GVim window and the latter restores it.
Full screen mode hides title bar, menu, toolbar and taskbar.
These are the toggle variants of the above functions. F10
will toggle maximized and F11
will toggle full screen. If you don't like these mappings, disable them in your vimrc
:
let g:vimdows_mappings = 0
When GVim is maximized or in full screen there's a bright frame on the right side and on the bottom side of the text area that does not match current GVim theme. To correct this you can use vimdows#fix_background
.
This function is called every time GVim gets maximized or enters full screen and also when changing themes when maximized or in full screen. You can opt-out in your vimrc
by:
let g:vimdows_background_fixes = 0
Then you will be able to use this function yourself.
In order to work, this requires the vimrc
changes described above. The following GVim window parameters are saved: position, size, is it maximized, is it full screen. The allowFullScreen
parameter can be used to force GVim to go out of full screen on next launch.
Your window will be saved when you exit GVim and restored when you launch GVim next time. You can disable this in your vimrc
like so:
let g:vimdows_screen_memento = 0
Lots of inspiration and some code taken from: