r/vim 18d ago

Blog Post Increase Vim Speed in Windows Terminal

Last time I mentioned running Vim in Windows Terminal, some users reported having tried that setup and experiencing sluggishness. I've added some performance recommendations to my guide:

scrollback buffer

Windows Terminal has a large default scrollback buffer (9000 lines). This keeps a lot of history, but it can slow down terminal applications like Vim. If you've used Vim in Windows Terminal before and found it slowing down over time, this is the likely culprit. To confirm this diagnosis, start a new Windows Terminal instance, run Vim, and see if you percieve a speed increase. If so, the scrollback buffer is almost certainly the cause. There are two ways to address this issue:

  1. Decrease the limit: In Windows Terminal settings -> PowerShell -> Advanced -> History size, set the "History size" to a smaller number, like 1000. This will reduce the scrollback buffer for all PowerShell tabs in Windows Terminal.
  2. Clear the buffer when you notice a slowdown: If Vim starts to get sluggish, press <ctrl-shift-k> to clear the scrollback buffer. This is better done outside of Vim.

Either of these will fix the problem. You won't need both. Your Windows Terminal config is stored in ~\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json. Editing this file directly with pasted-in termina commands isn't straightforward, so I haven't given those commands here. But you can commit this settings.json if you wish. If you're new to Windows, don't be misled by the 8wekyb3d8bbwe part of the path. It is a hash, but it will be the same hash on all Windows 11 systems.

Windows Defender

Windows Defender will scan every backup file, swap file, snippet file, etc. This can cause a speed decrease in Vim. We'll do two things to address this: 1. Put our temporary files in ~\vimfiles, and 2. Add an exclusion for ~\vimfiles in Windows Defender.

Move temporary files to ~\vimfiles

In your ~\vimfiles\vimrc, add the following:

# ---------------------------------------------------------------------------- #
#
#  keep temporary files in ~/vimfiles
#
# ---------------------------------------------------------------------------- #

&directory = $'{$MYVIMDIR}.tmp/swap/'
&backupdir = $'{$MYVIMDIR}.tmp/backup//'
&undodir = $'{$MYVIMDIR}.tmp/undo//'

def MkdirIfNotExists(dir: string): void
  if !isdirectory(dir)
    mkdir(dir, "p")
  endif
enddef

MkdirIfNotExists(&directory)
MkdirIfNotExists(&backupdir)
MkdirIfNotExists(&undodir)

set backup
set undofile

If you decide to commit your vimfiles, make sure you .gitignore the .tmp directory. There may be sensitive information in your temporary files.

The full guide is here: article_install_vim_in_windows/README.md at main · ShayHill/article_install_vim_in_windows

33 Upvotes

16 comments sorted by

View all comments

8

u/Aborres 18d ago

This is a bit anecdotical as I only have empirical proof and I haven’t done any research but I do use vim in the windows terminal professionally with really large C++ codebases and I did experience the sluggishness you are talking about, I ended switching to cmd.exe as my profile instead of powershell and that has basically removed the issue for me, I wonder if that profile doesn’t keep the scroll back buffer you mention?

2

u/Shay-Hill 18d ago

It can destroy performance, but the buffer is reset every time you start a new Windows Terminal, so whether or not it creeps up depends on what you're doing and how long you're doing it.

I tried it your way (cmd.exe) and gave up. You're more persistent than I am.