2023-02-20

VIM MSYS2/MINGW-64W Terminals

MSYS2/MINGW-64W terminals provide a Linux-like bash shell and a C compiler on Windows OS, as shown here they can be included inside the Windows Terminal application (wt.exe) with an ad-hoc profile.

Alternatively, this VIM9 plugin opens the same terminals in a VIM buffer. At the time of writing only msys2 and mingw64-w64 terminals are supported.

Assuming you are using this plugin manager, you need to add the plugin URL to your list in the .vimrc file, as follows:

   Plug 'https://sevepy@bitbucket.org/sevepy/vim-mterminals.git'

Save and source the rc file (:so %), and then run :PlugInstall.

You also need to create the following VIM global variable with the path to the msys2 root directory:

    if has('win32') || has('win64')
        " Set the Msys2 root directory
        let g:terminals_msys2_root = "C:\\msys2"
        " starting directory, optional
        let g:terminals_msys2_startingDirectory = "C:\\Users\\user"
    endif

It's also possible to define a default starting directory. Note that the backslash, that separates directories inside the path, has to be escaped.

This plugin provides the following mappings in normal mode:

leader m

Open or get back to a MSYS2 terminal buffer

leader M

Open or get back to a MINGW64-w64 terminal buffer

Here's a short demo.