A lightweight, seamless solution for compiling MQL5 (.mq5 / .mqh) files in Neovim on Linux using Wine, while mapping compilation errors directly back to your local repo's Quickfix list.
Running MetaEditor under Wine to build MQL5 scripts introduces several massive headaches that normally break stock build systems or standard Neovim compilers:
- The Space Curse: MetaEditor's CLI switch parser has a legendary bug when run inside Wine—if there are any spaces in your file paths, folder names, or inside your
#includestatement paths, compilation silently drops parameters or fails completely. - Log File Encoding: MetaEditor writes its compilation logs in
UTF-16LE(with standard Windows\r\ncarriage returns). Reading this natively in Linux results in garbage characters. - Path Resolution Matrix: The errors returned by MetaEditor point to Windows paths inside Wine (e.g.,
Z:\tmp\mql_build.XXXXXX\Strategy.mqh). Neovim has no native context to understand what file that actually corresponds to on your Linux system.
- Primes a Sandbox: It copies your active project files into a space-stripped temporary directory
/tmp/mql_build.XXXXXXand utilizes a RegEx engine (sed) to temporarily yank spaces out of local quote-enclosed#includestatements. - Pure Lua Pathing: It bypasses slow
winepathsystem forks by utilizing pure Lua path translation mechanics to construct nativeZ:\parameters. - Error De-serialization: It automatically processes the compilation log through
iconv, normalizes line endings, parses errors, maps the sandboxed file paths back to their original human-readable Linux project equivalents, and populates your Quickfix window.
To use this plugin, your Linux system must have the following dependencies installed:
- Wine (To execute
metaeditor64.exe) - iconv (Standard Linux utility used to transcode the UTF-16LE compiler logs to UTF-8)
- sed (Used to strip spaces dynamically inside sandbox includes)
Using lazy.nvim
return {
"yourusername/mql.nvim",
ft = { "mq5", "mqh" }, -- Lazy load only on MQL filetypes
opts = {
-- REQUIRED: Absolute path to your Wine MetaEditor executable
metaeditor_path = "~/.wine/drive_c/Program Files/MetaTrader 5/metaeditor64.exe",
-- REQUIRED: Absolute path to your default MQL5 standard components/include library folder
mql5_include_path = "~/.wine/drive_c/Program Files/MetaTrader 5/MQL5",
-- OPTIONAL: Default mapping to trigger compilation (set to `false` to disable)
bind_key = "<F7>",
}
}- Open any .mq5 file.
- Press F7 (or your custom bound key) to compile.
- If compilation succeeds, an .ex5 binary will be placed side-by-side with your code.
- If compilation fails, the Quickfix window will automatically pop open.
- Pressing l or inside the Quickfix window will jump directly to the line containing the error.